Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Varriount/37c0a0cc77982d790bb625bb83306caa to your computer and use it in GitHub Desktop.
Save Varriount/37c0a0cc77982d790bb625bb83306caa to your computer and use it in GitHub Desktop.
# 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