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"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
|
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 showVersion *bool = flag.Bool("v", false, "show version")
|
||||||
|
|
||||||
var version string
|
var version string
|
||||||
@ -32,11 +35,24 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
var network string
|
||||||
if typ, addr := config.SplitNetworkAddress(); typ == "unix" {
|
if !strings.ContainsRune(*listenAddress, ':') {
|
||||||
os.Remove(addr)
|
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)
|
logErr, err := logging.New(config.Log.Error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -83,7 +99,7 @@ func main() {
|
|||||||
srv.GET("/f/:hash/:name", hand.Download)
|
srv.GET("/f/:hash/:name", hand.Download)
|
||||||
srv.DELETE("/:hash", hand.Delete)
|
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)
|
logErr.Fatalln("failed to start a server:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user