-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
593 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
CC = gcc | ||
# WARN: you should run the binaries with LD_LIBRARY_PATH=../dist | ||
|
||
# you should run the binaries with LD_LIBRARY_PATH=../dist | ||
CC = gcc | ||
INCD = ../inc | ||
DIST = ../dist | ||
|
||
all: ../dist/example_hello ../dist/example_echo ../dist/example_middleware | ||
DIRS = $(shell find * -maxdepth 0 -type d) | ||
BINS = $(patsubst %,$(DIST)/example_%,$(DIRS)) | ||
|
||
../dist/libctorm.so: | ||
ifeq (,$(wildcard ../dist/libctorm.so)) | ||
@echo "!!!! you should first compile libctorm !!!!" | ||
all: $(BINS) | ||
|
||
$(DIST)/libctorm.so: | ||
ifeq (,$(wildcard $(DIST)/libctorm.so)) | ||
@echo "you should first compile libctorm" | ||
exit 1 | ||
endif | ||
|
||
../dist/example_hello: hello/*.c ../dist/libctorm.so | ||
mkdir -pv ../dist | ||
$(CC) -I../inc -L../dist hello/*.c -lctorm -o $@ | ||
|
||
../dist/example_echo: echo/*.c ../dist/libctorm.so | ||
mkdir -pv ../dist | ||
$(CC) -I../inc -L../dist echo/*.c -lctorm -o $@ | ||
|
||
../dist/example_middleware: middleware/*.c ../dist/libctorm.so | ||
mkdir -pv ../dist | ||
$(CC) -I../inc -L../dist middleware/*.c -lctorm -lcjson -o $@ | ||
$(DIST)/example_%: %/main.c $(DIST)/libctorm.so | ||
@mkdir -pv $(DIST) | ||
$(CC) -I$(INCD) -L$(DIST) $< -lctorm -lcjson -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM ghcr.io/ngn13/ctorm:latest | ||
|
||
WORKDIR /example/params | ||
COPY main.c ./ | ||
|
||
# examples uses the local headers, replace it with the global ones | ||
RUN gcc -O3 -o /app main.c -lctorm | ||
|
||
WORKDIR / | ||
CMD ["/app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <ctorm.h> | ||
|
||
void GET_index(ctorm_req_t *req, ctorm_res_t *res) { | ||
RES_REDIRECT("/echo/changeme/nothing"); | ||
} | ||
|
||
void GET_param(ctorm_req_t *req, ctorm_res_t *res) { | ||
RES_FMT("param: %s", REQ_PARAM("param")); | ||
} | ||
|
||
int main() { | ||
// create the app | ||
ctorm_app_t *app = ctorm_app_new(NULL); | ||
|
||
// setup the routes | ||
GET(app, "/", GET_index); | ||
GET(app, "/echo/:param/*", GET_param); | ||
|
||
// run the app | ||
if (!ctorm_app_run(app, "0.0.0.0:8080")) | ||
ctorm_fail("failed to start the app: %s", ctorm_geterror()); | ||
|
||
// clean up | ||
ctorm_app_free(app); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#ifndef CTROM_EXPORT | ||
|
||
typedef struct ctorm_pair { | ||
char *key, *value; | ||
struct ctorm_pair *next; | ||
} ctorm_pair_t; | ||
|
||
ctorm_pair_t *ctorm_pair_add(ctorm_pair_t **head, char *key, char *value); | ||
#define ctorm_pair_next(head, cur) for (ctorm_pair_t *cur = head; cur != NULL; cur = cur->next) | ||
ctorm_pair_t *ctorm_pair_find(ctorm_pair_t *head, char *key); | ||
void ctorm_pair_free(ctorm_pair_t *head); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.