8000 GitHub - peterbourgon/unixtransport: Support for Unix domain sockets in Go HTTP clients
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

peterbourgon/unixtransport

Repository files navigation

unixtransport Go Reference Latest Release Tests

This package adds support for Unix sockets to Go HTTP clients and servers.

Clients

Register the Unix protocol in the default HTTP client transport like this:

unixtransport.RegisterDefault()

Now you can make HTTP requests with URLs like this:

resp, err := http.Get("http+unix:///path/to/socket:/request/path?a=b#fragment")

Use scheme http+unix or https+unix, and use : to separate the socket file path (host) from the URL request path.

See e.g. Register and RegisterDefault for more info.

Servers

If you have this:

fs := flag.NewFlagSet("myserver")
addr := fs.String("addr", ":8080", "listen address")
...
http.ListenAndServe(*addr, nil)

You can change it like this:

 fs := flag.NewFlagSet("myserver")
 addr := fs.String("addr", ":8080", "listen address")
 ...
-http.ListenAndServe(*addr, nil)
+ln, err := ListenURI(context.TODO(), *addr)
+// handle err
+http.Serve(ln, nil)

Which lets you specify addrs like this:

myserver -addr=unix:///tmp/mysocket

See e.g. ParseURI and ListenURI for more info.

Acknowledgements

Inspiration taken from, and thanks given to, both tv42/httpunix and agorman/httpunix.

About

Support for Unix domain sockets in Go HTTP clients

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

2977
0