-
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.
fix locals macro and add new example for locals
Signed-off-by: ngn <[email protected]>
- Loading branch information
Showing
20 changed files
with
126 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM ghcr.io/ngn13/ctorm:latest | ||
|
||
WORKDIR /example | ||
COPY . ./ | ||
|
||
RUN mkdir /dist | ||
RUN make \ | ||
DONT_CHECK_LIBCTORM=1 \ | ||
INCD=/usr/include/ctorm \ | ||
DIST=/dist | ||
|
||
WORKDIR / | ||
CMD ["/example/init.sh"] |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,24 @@ | ||
#!/bin/bash | ||
|
||
# docker init script | ||
|
||
examples=() | ||
pids=() | ||
|
||
for example in dist/*; do | ||
examples+=("${example}") | ||
done | ||
|
||
for i in "${!examples[@]}"; do | ||
"./${examples[$i]}" & | ||
pids[$i]=$! | ||
done | ||
|
||
for i in "${!pids[@]}"; do | ||
if ! wait "${pids[$i]}"; then | ||
echo "${examples[$i]} exited with a non zero exit-code (${?})" | ||
exit 1 | ||
fi | ||
done | ||
|
||
exit 0 |
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,34 @@ | ||
#include <ctorm.h> | ||
|
||
void GET_index(ctorm_req_t *req, ctorm_res_t *res) { | ||
char *username = REQ_LOCAL("username"); | ||
RES_FMT("username: %s", username); | ||
} | ||
|
||
void username_middleware(ctorm_req_t *req, ctorm_res_t *res) { | ||
char *username = REQ_QUERY("username"); | ||
|
||
if (NULL == username) { | ||
RES_SEND("no username provided"); | ||
REQ_CANCEL(); | ||
return; | ||
} | ||
|
||
REQ_LOCAL("username", username); | ||
} | ||
|
||
int main() { | ||
// create the app | ||
ctorm_app_t *app = ctorm_app_new(NULL); | ||
|
||
// setup the routes | ||
MIDDLEWARE_GET(app, "/*", username_middleware); | ||
GET(app, "/", GET_index); | ||
|
||
// run the app | ||
if (!ctorm_app_run(app, "0.0.0.0:8083")) | ||
ctorm_fail("failed to start the app: %s", ctorm_geterror()); | ||
|
||
// clean up | ||
ctorm_app_free(app); | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
#!/bin/bash | ||
|
||
no_user=$(curl --silent -w "%{http_code}" 'http://127.0.0.1:8083/') | ||
with_user=$(curl --silent -w "%{http_code}" 'http://127.0.0.1:8083/?username=ngn') | ||
|
||
if [[ "${no_user}" != "no username provided200" ]]; then | ||
echo 'fail (1)' | ||
exit 1 | ||
fi | ||
|
||
if [[ "${with_user}" != "username: ngn200" ]]; then | ||
echo 'fail (2)' | ||
exit 1 | ||
fi | ||
|
||
echo 'success' |
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