Skip to content

Commit

Permalink
Allow listening on unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
gvalkov committed Jul 17, 2018
1 parent 450ab86 commit 1495f2c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions main.go
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/pelletier/go-toml"
flag "github.com/spf13/pflag"
"log"
"net"
"os"
"strings"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ more configurability than the command-line interface.
# The root of the web application.
relative-root = "/"
# The address to listen on.
# The address to listen on. Can be an address:port combination or an unix socket.
listen-addr = ":8080"
# Allow download of know files (only those matched by a filespec).
Expand Down Expand Up @@ -278,5 +279,21 @@ func main() {
loggerHTML.Printf("Server start, relative-root: %s, bind-addr: %s\n", config.RelativeRoot, config.BindAddr)

server := setupServer(config, loggerHTML)
server.ListenAndServe()

if strings.Contains(config.BindAddr, ":") {
server.ListenAndServe()
} else {
os.Remove(config.BindAddr)

unixAddr, _ := net.ResolveUnixAddr("unix", config.BindAddr)
unixListener, err := net.ListenUnix("unix", unixAddr)
unixListener.SetUnlinkOnClose(true)

if err != nil {
panic(err)
}

defer unixListener.Close()
server.Serve(unixListener)
}
}

0 comments on commit 1495f2c

Please sign in to comment.