Skip to content
Snippets Groups Projects
Verified Commit 2ac4ee4e authored by Ophestra's avatar Ophestra
Browse files

feat(serve): listen on unix socket


Support listening on unix socket. Path is set by the LISTEN environment variable.

Signed-off-by: default avatarOphestra Umiker <cat@ophivana.moe>
parent 7cb0a36e
No related branches found
No related tags found
1 merge request!7feat(serve): listen on unix socket
Pipeline #968 passed
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net"
"os" "os"
"sync/atomic" "sync/atomic"
"time" "time"
...@@ -73,5 +74,13 @@ func serve(sig chan os.Signal, db *leveldb.DB) error { ...@@ -73,5 +74,13 @@ func serve(sig chan os.Signal, db *leveldb.DB) error {
} }
}() }()
if conf[listen] == "unset" {
return app.Listen(conf[listenAddr]) return app.Listen(conf[listenAddr])
} else {
if l, err := net.Listen("unix", conf[listen]); err != nil {
return err
} else {
return app.Listener(l)
}
}
} }
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
const ( const (
dbPath uint8 = iota dbPath uint8 = iota
listen
listenAddr listenAddr
allowedURL allowedURL
hCaptchaSiteKey hCaptchaSiteKey
...@@ -17,6 +18,7 @@ const ( ...@@ -17,6 +18,7 @@ const (
// env variable, default pairing // env variable, default pairing
var confEnv = [...][2]string{ var confEnv = [...][2]string{
dbPath: {"DB", "db"}, dbPath: {"DB", "db"},
listen: {"LISTEN", "unset"},
listenAddr: {"LISTEN_ADDR", "127.0.0.1:3000"}, listenAddr: {"LISTEN_ADDR", "127.0.0.1:3000"},
allowedURL: {"ALLOWED_URL", "https://hizla.io"}, allowedURL: {"ALLOWED_URL", "https://hizla.io"},
hCaptchaSiteKey: {"HCAPTCHA_SITE_KEY", "unset"}, hCaptchaSiteKey: {"HCAPTCHA_SITE_KEY", "unset"},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment