Create golang http.Server for different listen address types
Go to file
2023-05-09 22:45:52 -04:00
examples/idle_server_shutdown Add example for idle 2023-05-09 22:45:52 -04:00
idle Add example for idle 2023-05-09 22:45:52 -04:00
anyhttp.go Refactor environment parsing 2023-04-30 23:37:46 -04:00
go.mod initial version 2023-04-20 16:31:35 -04:00
LICENSE initial version 2023-04-20 16:31:35 -04:00
README.md Add links and documentation 2023-04-25 09:14:16 -04:00

Create http server listening on unix sockets or 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 to socket>

Examples

unix/relative/path.sock
unix//var/run/app/absolutepath.sock

Systemd Socket activated fd:

Syntax

sysd/fdidx/<fd index starting at 0>
sysd/fdname/<fd name set using FileDescriptorName socket setting >

Examples:

# First (or only) socket fd passed to app
sysd/fdidx/0

# Socket with FileDescriptorName
sysd/fdname/myapp

# Using default name
sysd/fdname/myapp.socket

TCP port

If the address is a number less than 65536, it is assumed as a port and passed as http.ListenAndServe(":<port>",...)

Anything else is directly passed to http.ListenAndServe as well. Below examples should work

:http
:8888
127.0.0.1:8080

Documentation

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