Pass listen address as a -listen argument. Use the new code to parse a parameter.
This commit is contained in:
parent
ce6d81ad55
commit
c43c314a78
@ -9,12 +9,15 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
||||
var listenAddress *string = flag.String("listen", "/var/run/dwelling-upload/sock", "listen address (ip:port|unix_path)")
|
||||
var showVersion *bool = flag.Bool("v", false, "show version")
|
||||
|
||||
var version string
|
||||
@ -32,11 +35,24 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if typ, addr := config.SplitNetworkAddress(); typ == "unix" {
|
||||
os.Remove(addr)
|
||||
var network string
|
||||
if !strings.ContainsRune(*listenAddress, ':') {
|
||||
network = "unix"
|
||||
defer os.Remove(*listenAddress)
|
||||
} else {
|
||||
ap, err := netip.ParseAddrPort(*listenAddress)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
} else if !ap.IsValid() {
|
||||
log.Fatalln(*listenAddress, "is not valid")
|
||||
}
|
||||
}()
|
||||
|
||||
if ap.Addr().Is4() {
|
||||
network = "tcp4"
|
||||
} else if ap.Addr().Is6() {
|
||||
network = "tcp6"
|
||||
}
|
||||
}
|
||||
|
||||
logErr, err := logging.New(config.Log.Error)
|
||||
if err != nil {
|
||||
@ -83,7 +99,7 @@ func main() {
|
||||
srv.GET("/f/:hash/:name", hand.Download)
|
||||
srv.DELETE("/:hash", hand.Delete)
|
||||
|
||||
if err := srv.Start(config.SplitNetworkAddress()); err != nil {
|
||||
if err := srv.Start(network, *listenAddress); err != nil {
|
||||
logErr.Fatalln("failed to start a server:", err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user