mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-02-15 22:10:04 +00:00
feat: add unix socket support (#615)
This commit is contained in:
@@ -101,21 +101,27 @@ func initRouterInternal(db *gorm.DB, svc *services) (utils.Service, error) {
|
|||||||
|
|
||||||
// Set up the server
|
// Set up the server
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: net.JoinHostPort(common.EnvConfig.Host, common.EnvConfig.Port),
|
|
||||||
MaxHeaderBytes: 1 << 20,
|
MaxHeaderBytes: 1 << 20,
|
||||||
ReadHeaderTimeout: 10 * time.Second,
|
ReadHeaderTimeout: 10 * time.Second,
|
||||||
Handler: r,
|
Handler: r,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the listener
|
// Set up the listener
|
||||||
listener, err := net.Listen("tcp", srv.Addr)
|
network := "tcp"
|
||||||
|
addr := net.JoinHostPort(common.EnvConfig.Host, common.EnvConfig.Port)
|
||||||
|
if common.EnvConfig.UnixSocket != "" {
|
||||||
|
network = "unix"
|
||||||
|
addr = common.EnvConfig.UnixSocket
|
||||||
|
}
|
||||||
|
|
||||||
|
listener, err := net.Listen(network, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create TCP listener: %w", err)
|
return nil, fmt.Errorf("failed to create %s listener: %w", network, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service runner function
|
// Service runner function
|
||||||
runFn := func(ctx context.Context) error {
|
runFn := func(ctx context.Context) error {
|
||||||
log.Printf("Server listening on %s", srv.Addr)
|
log.Printf("Server listening on %s", addr)
|
||||||
|
|
||||||
// Start the server in a background goroutine
|
// Start the server in a background goroutine
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type EnvConfigSchema struct {
|
|||||||
KeysPath string `env:"KEYS_PATH"`
|
KeysPath string `env:"KEYS_PATH"`
|
||||||
Port string `env:"PORT"`
|
Port string `env:"PORT"`
|
||||||
Host string `env:"HOST"`
|
Host string `env:"HOST"`
|
||||||
|
UnixSocket string `env:"UNIX_SOCKET"`
|
||||||
MaxMindLicenseKey string `env:"MAXMIND_LICENSE_KEY"`
|
MaxMindLicenseKey string `env:"MAXMIND_LICENSE_KEY"`
|
||||||
GeoLiteDBPath string `env:"GEOLITE_DB_PATH"`
|
GeoLiteDBPath string `env:"GEOLITE_DB_PATH"`
|
||||||
GeoLiteDBUrl string `env:"GEOLITE_DB_URL"`
|
GeoLiteDBUrl string `env:"GEOLITE_DB_URL"`
|
||||||
@@ -51,6 +52,7 @@ var EnvConfig = &EnvConfigSchema{
|
|||||||
AppURL: "http://localhost:1411",
|
AppURL: "http://localhost:1411",
|
||||||
Port: "1411",
|
Port: "1411",
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
|
UnixSocket: "",
|
||||||
MaxMindLicenseKey: "",
|
MaxMindLicenseKey: "",
|
||||||
GeoLiteDBPath: "data/GeoLite2-City.mmdb",
|
GeoLiteDBPath: "data/GeoLite2-City.mmdb",
|
||||||
GeoLiteDBUrl: MaxMindGeoLiteCityUrl,
|
GeoLiteDBUrl: MaxMindGeoLiteCityUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user