Go buildmodes prototype: Expose net/http.Server as a library with C bindings
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
Shared library that exposes Go's
net/http.Serverwith externally-bindable handlers.
This is a silly project for experimenting with Go buildmodes. I gave a talk about this at PyCon 2016.
Status: Tiny subset of the
http.HandlerFunccallback gets passed to a C handler callback. Python bindings are working, too.
$ git clone https://github.com/shazow/gohttplib/ $ cd gohttplib $ make examples
C example can be linked against a shared object (
go build -buildmode=c-shared) or against a static library archive (
go build -buildmode=c-archive). By default, we link against the shared object because that's what the Python example uses too.
Linked against our shared object:
$ make example-c $ DYLD_LIBRARY_PATH=build/ ./build/gohttp-c
Note that you'll need to make sure that
libgohttp.sois findable at runtime.
Now you can request
http://localhost:8000/helloand the C handler in
examples/c/main.cwill handle it!
Linked against our static library archive:
$ make example-c-static $ ./build/gohttp-c-static
The static archive gets built into the binary so it's more portable during runtime. Note the size differences:
8.8K gohttp-c 5.1M gohttp-c-static 7.5M libgohttp.a 6.9M libgohttp.so
The Python example uses python-cffi (you'll need python-cffi installed) to link against the shared object.
$ make example-python $ cd examples/python $ python -m gohttp * Running on http://127.0.0.1:5000/
Or write your own handler using this library:
from gohttp import route, run
@route('/') def index(w, req): w.write("%s %s %s\n" % (req.method, req.host, req.url)) w.write("Hello, world.\n")
This project was made possible thanks to Glider Labs.