2023-04-20 16:31:35 -04:00
|
|
|
Create http server listening on unix sockets or systemd socket activated fds
|
|
|
|
|
|
|
|
## Quick Usage
|
|
|
|
|
2023-04-25 09:14:16 -04:00
|
|
|
go get go.balki.me/anyhttp
|
|
|
|
|
2023-04-20 16:31:35 -04:00
|
|
|
Just replace `http.ListenAndServe` with `anyhttp.ListenAndServe`.
|
|
|
|
|
|
|
|
```diff
|
|
|
|
- http.ListenAndServe(addr, h)
|
|
|
|
+ anyhttp.ListenAndServe(addr, h)
|
|
|
|
```
|
|
|
|
|
2023-04-20 17:56:44 -04:00
|
|
|
## Address Syntax
|
2023-04-20 16:31:35 -04:00
|
|
|
|
2023-04-20 17:56:44 -04:00
|
|
|
### Unix socket
|
2023-04-20 16:31:35 -04:00
|
|
|
|
|
|
|
Syntax
|
|
|
|
|
|
|
|
unix/<path to socket>
|
|
|
|
|
|
|
|
Examples
|
|
|
|
|
|
|
|
unix/relative/path.sock
|
|
|
|
unix//var/run/app/absolutepath.sock
|
|
|
|
|
2023-04-20 17:56:44 -04:00
|
|
|
### Systemd Socket activated fd:
|
2023-04-20 16:31:35 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-04-20 17:56:44 -04:00
|
|
|
### TCP port
|
2023-04-20 16:31:35 -04:00
|
|
|
|
|
|
|
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
|
2023-04-25 09:14:16 -04:00
|
|
|
|
|
|
|
## Documentation
|
|
|
|
|
|
|
|
https://pkg.go.dev/go.balki.me/anyhttp
|
|
|
|
|
|
|
|
### Related links
|
|
|
|
|
|
|
|
* https://gist.github.com/teknoraver/5ffacb8757330715bcbcc90e6d46ac74#file-unixhttpd-go
|
|
|
|
* https://github.com/coreos/go-systemd/tree/main/activation
|