diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-04-27 13:50:27 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-04-27 18:25:53 +0300 |
commit | 60e9cfb7e61fe9eb7141cc9e7d6e95495048bb37 (patch) | |
tree | e193f614f1b5454e7787b3d0acceb6e53a058bdd /server.go | |
parent | 46b4706ea917e4e5018c455d6737893d9426aada (diff) |
Add support for socket listeners
Changelog: added
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -7,6 +7,7 @@ import ( stdlog "log" "net" "net/http" + "path/filepath" "github.com/pires/go-proxyproto" "github.com/sirupsen/logrus" @@ -47,7 +48,7 @@ func (a *theApp) listenAndServe(server *http.Server, addr string, h http.Handler KeepAlive: a.config.Server.ListenKeepAlive, } - l, err := lc.Listen(context.Background(), "tcp", addr) + l, err := listenAddr(context.Background(), &lc, addr) if err != nil { return fmt.Errorf("failed to listen on addr %s: %w", addr, err) } @@ -77,6 +78,14 @@ func (a *theApp) listenAndServe(server *http.Server, addr string, h http.Handler return server.Serve(l) } +func listenAddr(ctx context.Context, lc *net.ListenConfig, address string) (net.Listener, error) { + if filepath.IsAbs(address) { + return lc.Listen(ctx, "unix", address) + } + + return lc.Listen(ctx, "tcp", address) +} + type option func(*listenerConfig) func withProxyV2() option { |