mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
Support Unix domain sockets for proxy server listener (#1865)
This commit is contained in:
+23
-5
@@ -6,6 +6,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
@@ -45,7 +46,6 @@ func main() {
|
||||
}
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: conf.Port,
|
||||
Handler: handler,
|
||||
ReadHeaderTimeout: 2 * time.Second,
|
||||
}
|
||||
@@ -75,11 +75,29 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
log.Printf("Starting application at port %v", conf.Port)
|
||||
if cert != "" && key != "" {
|
||||
err = srv.ListenAndServeTLS(conf.TLSCertFile, conf.TLSKeyFile)
|
||||
// Unix socket configuration, if available, takes precedence over TCP port configuration.
|
||||
var ln net.Listener
|
||||
|
||||
if conf.UnixSocket != "" {
|
||||
log.Printf("Starting application at Unix domain socket %v", conf.UnixSocket)
|
||||
|
||||
ln, err = net.Listen("unix", conf.UnixSocket)
|
||||
if err != nil {
|
||||
log.Fatalf("error listening on Unix domain socket %v: %v", conf.UnixSocket, err)
|
||||
}
|
||||
} else {
|
||||
err = srv.ListenAndServe()
|
||||
log.Printf("Starting application at port %v", conf.Port)
|
||||
|
||||
ln, err = net.Listen("tcp", conf.Port)
|
||||
if err != nil {
|
||||
log.Fatalf("error listening on TCP port %v: %v", conf.Port, err)
|
||||
}
|
||||
}
|
||||
|
||||
if cert != "" && key != "" {
|
||||
err = srv.ServeTLS(ln, conf.TLSCertFile, conf.TLSKeyFile)
|
||||
} else {
|
||||
err = srv.Serve(ln)
|
||||
}
|
||||
|
||||
if !errors.Is(err, http.ErrServerClosed) {
|
||||
|
||||
@@ -131,6 +131,12 @@ StorageType = "memory"
|
||||
# The PORT must be a number or a number prefixed by ":"
|
||||
Port = ":3000"
|
||||
|
||||
# UnixSocket sets a Unix domain socket path that the proxy listens on.
|
||||
# This option, when specified, takes precedence over TCP port configuration.
|
||||
# Defaults to empty (i.e. listen on a TCP port only)
|
||||
# Env override: ATHENS_UNIX_SOCKET
|
||||
UnixSocket = ""
|
||||
|
||||
# The endpoint for a package registry in case of a proxy cache miss
|
||||
# NOTE: Currently no registries have been implemented
|
||||
# Env override: ATHENS_GLOBAL_ENDPOINT
|
||||
|
||||
@@ -38,6 +38,7 @@ type Config struct {
|
||||
StorageType string `validate:"required" envconfig:"ATHENS_STORAGE_TYPE"`
|
||||
GlobalEndpoint string `envconfig:"ATHENS_GLOBAL_ENDPOINT"` // This feature is not yet implemented
|
||||
Port string `envconfig:"ATHENS_PORT"`
|
||||
UnixSocket string `envconfig:"ATHENS_UNIX_SOCKET"`
|
||||
BasicAuthUser string `envconfig:"BASIC_AUTH_USER"`
|
||||
BasicAuthPass string `envconfig:"BASIC_AUTH_PASS"`
|
||||
ForceSSL bool `envconfig:"PROXY_FORCE_SSL"`
|
||||
|
||||
Reference in New Issue
Block a user