• Stars
    star
    209
  • Rank 188,325 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go buildmodes prototype: Expose net/http.Server as a library with C bindings

gohttplib

Shared library that exposes Go's net/http.Server with 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.HandlerFunc callback gets passed to a C handler callback. Python bindings are working, too.

Getting Started

Requirements:

  • Go 1.5 or newer.
  • C example: make, gcc
  • Python example: cffi, python-cffi
$ git clone https://github.com/shazow/gohttplib/
$ cd gohttplib
$ make examples

Example: C

C example can be linked against a shared object (libgohttp.so generated by go build -buildmode=c-shared) or against a static library archive (libgohttp.a generated by 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.so is findable at runtime.

Now you can request http://localhost:8000/hello and the C handler in examples/c/main.c will 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

Example: Python

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")

run(host='127.0.0.1', port=5000)

References & Credit

Sponsors

This project was made possible thanks to Glider Labs.

License

MIT

More Repositories

1

ssh-chat

Chat over SSH.
Go
5,180
star
2

whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
TypeScript
1,015
star
3

workerpool

Python multithreaded job distribution module.
Python
152
star
4

unstdlib.py

Unstandard Python library of useful and highly-reusable functions.
Python
146
star
5

ethspam

Generate realistic Ethereum JSONRPC queries, useful for benchmarking and testing.
Go
89
star
6

apiclient

Framework for making good Python API client libraries using urllib3.
Python
87
star
7

foundry.nix

Nix overlay for gakonst/foundry (including forge and cast)
Nix
54
star
8

callthis

Build a transaction, send a link for someone else to execute it.
Svelte
45
star
9

dotfiles

Some of my . files.
Vim Script
44
star
10

composer

Static website generator, structure/syntax-agnostic.
Python
44
star
11

communal

WIP: Automating doom-scrolling
Go
44
star
12

go-selfcompile

Build self-recompiling Go binaries
Go
39
star
13

nixfiles

Some of my .nix files
Nix
32
star
14

grid-benchmark.js

Benchmark of Javascript grid datastructures
JavaScript
29
star
15

shazow.net

CSS
26
star
16

go-irckit

Minimal IRC server (and maybe client) toolkit for Go.
Go
24
star
17

briefmetrics

Briefmetrics emails you simple overviews of your website's Google Analytics.
Python
23
star
18

sqlalchemygrate

Silly (but effective) database schema and data migration framework using SQLAlchemy.
Python
23
star
19

btc-crawl

Bitcoin node network crawler (written in Go).
Go
23
star
20

colorblendy

Blend colors with different modes like multiply, overlay, dodge.
JavaScript
22
star
21

learning-opengl

My notes from learning OpenGL
Shell
21
star
22

go-sshkit

Toolkit for building SSH servers and clients in Go.
Go
21
star
23

colorlib

Collection of color manipulation functions in Javascript.
JavaScript
16
star
24

neobnc

Multi-tenant IRC bouncer (BNC), written in Go.
Go
13
star
25

ssh-hammer

SSH load testing tool.
Go
13
star
26

liquid

Arbitrage bot to provide liquidity between two Bitcoin exchanges.
JavaScript
12
star
27

gameblocks.js

Game engine framework for JavaScript, used to make LineRage.
JavaScript
12
star
28

relay.js

Host a JavaScript server in your browser.
JavaScript
11
star
29

go-diff

Library for generating Git-style diff patchsets in Go.
Go
9
star
30

memoizer

Golang memoizer interface for caching your function calls.
Go
9
star
31

keyxor

Keyxor Sรถze, a ๐Ÿ”‘ splitting and merging tool for secret sharing
Go
8
star
32

bashbnc

Single-user IRC bouncer (BNC), written in Bash.
Shell
8
star
33

flashbots-boilerplate

Messing around with Flashbots and Deno
TypeScript
7
star
34

everything

My writing about everything.
7
star
35

go-webrtc-server

http middleware for auto-negotiating a server-to-client WebRTC connection.
Go
7
star
36

turnip

Turnip Task Scheduler: Like celery but tastier.
Python
6
star
37

wideslide

jQuery plugin for a landscape-scrolling image slideshow.
JavaScript
6
star
38

stripe-copy

Copy Stripe objects like subscriptions and plans between accounts.
Go
6
star
39

clog

Command Log. Or Captain's Log.
Python
6
star
40

go-gameblocks

Game engine toolkit for Go.
Go
5
star
41

wedomainsearch

Realtime collaborative domain search
CSS
5
star
42

tweography

Your tweets on a map.
JavaScript
5
star
43

tbd

Name not determined yet.
4
star
44

clicker.go

An incremental game about Go programming.
Go
4
star
45

dockerfiles

A shipyard for my dockers.
Shell
4
star
46

twebbie

Javascript Twitter client with group support like TweetDeck.
JavaScript
4
star
47

iwascaught.com

JavaScript
3
star
48

0xBozos

EVM programming puzzle game.
Nix
3
star
49

tweepsect

Twitter stalkers exposed.
JavaScript
3
star
50

coinhooks

A webhooks service for Bitcoin ecommerce.
Python
3
star
51

data

Dump of data generated by me.
Python
3
star
52

rnges.us

Instant collaborative RNG, send a link to your friend and off you go
3
star
53

302found

Simple redireciton web service built on the Google App Engine platform.
Python
3
star
54

linerage3d

experimental: Remake of LineRage in 3D using Go
Go
3
star
55

pyramid_scaffolds_decoupled

Decouple web-specific code from the models, libraries, and apis, so that the components can be used independently.
Python
3
star
56

garlic

Garlic is a language agnostic task scheduler. [DRAFT]
2
star
57

eip-sighashes

Ethereum 4-byte signature hashes extracted from EIPs
Nix
2
star
58

ssh-chat-relay

Relay your ssh-chat server to other protocols, like websocket.
Go
2
star
59

go-multierror

Another MultiError implementation for Go.
Go
2
star
60

unstdlib.js

Unstandard JavaScript library of useful and highly-reusable functions.
JavaScript
2
star
61

phantomd3

Render d3.js charts inside PhantomJS
JavaScript
2
star
62

splitcost

Simple AngularJS to account shared expenses for a trip.
JavaScript
2
star
63

176

Repo number one hundred and seventy six
1
star
64

shazow.github.com

Me
1
star
65

ssh-blog

Why would anyone do this, you might ask yourself. You'd be correct to ask yourself that.
1
star
66

fwdup

Git-based backups.
Shell
1
star
67

linerage

You're a line, don't hit each other. (Pushed for posterity)
JavaScript
1
star
68

sometalk-test

Messing around for a talk.
Python
1
star
69

learning-rust

Playing around with some Rust code.
Rust
1
star
70

instantlyat

Old project I worked on with @dsa
Python
1
star
71

go-ipfs-extracted

Extracted packages from go-ipfs
Go
1
star
72

viprpc

WIP: Prototyping a web3 RPC MITM for capturing and analyzing some kinds of transactions
Go
1
star
73

contract-explorer

Like Internet Explorer, but for Contracts.
Svelte
1
star
74

ens-managed-registry

Collection of ENS components for operating a managed registry (subdomains controlled by an oracle).
Solidity
1
star
75

salt-states

My lovely salty salt states.
Scheme
1
star
76

chessviz

Visualizing chess games with three.js
JavaScript
1
star
77

cosm

WIP: Embedded worlds
1
star
78

rateio

Ratelimiting for io-style interfaces in Go.
Go
1
star