Created
July 9, 2020 20:24
-
-
Save Varriount/37c0a0cc77982d790bb625bb83306caa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Compile with --gc:arc | |
import ngxcmod, strutils | |
proc init(ctx: ContextCycle) {.exportc: "ngx_link_func_init_cycle", dynlib, cdecl.} = | |
setupForeignThreadGc() | |
ctx.cyc_log(INFO, "hello from Nim") | |
proc exit(ctx: ContextCycle) {.exportc: "ngx_link_func_exit_cycle", dynlib, cdecl.} = | |
setupForeignThreadGc() | |
ctx.cyc_log(WARN, "goodbye, from Nim w/ <3") | |
proc hello(ctx: Context) {.exportc, dynlib, cdecl.} = | |
setupForeignThreadGc() | |
ctx.log(INFO, "Calling back and log from hello") | |
let | |
name = ctx.getQueryParam("name") | |
message = "hello $#, greeting from Nim" % name | |
ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, message) | |
proc post(ctx: Context) {.exportc, dynlib, cdecl.} = | |
setupForeignThreadGc() | |
ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, ctx.getBodyAsStr()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment