Skip to content

Repository files navigation

Create http server listening on unix sockets and systemd socket activated fds

Quick Usage

go get go.balki.me/anyhttp

Just replace http.ListenAndServe with anyhttp.ListenAndServe.

- http.ListenAndServe(addr, h)+ anyhttp.ListenAndServe(addr, h)

Address Syntax

Unix socket

Syntax

unix?path=<socket_path>&mode=<socket file mode>&remove_existing=<true|false>

Examples

unix?path=relative/path.sock
unix?path=/var/run/app/absolutepath.sock
unix?path=/run/app.sock&mode=600&remove_existing=false
optiondescriptiondefault
pathpath to unix socketRequired
modesocket file mode666
remove_existingWhether to remove existing socket file or failtrue

Systemd Socket activated fd:

Syntax

sysd?idx=<fd index>&name=<fd name>&check_pid=<true|false>&unset_env=<true|false>&idle_timeout=<duration>

Only one of idx or name has to be set

Examples:

# First (or only) socket fd passed to app
sysd?idx=0
# Socket with FileDescriptorName
sysd?name=myapp
# Using default name and auto shutdown if no requests received in last 30 minutes
sysd?name=myapp.socket&idle_timeout=30m
optiondescriptiondefault
nameName configured via FileDescriptorName or socket file nameRequired
idxFD Index. Actual fd num will be 3 + idxRequired
idle_timeouttime to wait before shutdown. syntaxno auto shutdown
check_pidCheck process PID matches LISTEN_PIDtrue
unset_envUnsets the LISTEN* environment variables, so they don't get passed to any child processestrue

TCP

If the address is not one of above, it is assumed to be tcp and passed to http.ListenAndServe.

Examples:

:http
:8888
127.0.0.1:8080

Documentation

https://pkg.go.dev/go.balki.me/anyhttp

Related links

About

go module to create http server listening on unix sockets / systemd socket activated fds

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages