Listen http server in main thread

This commit is contained in:
2021-12-03 02:26:58 +01:00
parent c20306c118
commit b106844c22
2 changed files with 30 additions and 0 deletions
+31 -2
View File
@@ -2,9 +2,11 @@ package main
import (
"fmt"
"net"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/valyala/fasthttp"
"code.tokarch.uk/mainnika/nikita-tokarch-uk/frontend/config"
)
@@ -28,6 +30,33 @@ func main() {
logrus.Warnf("Cannot unmarshal config, %v", err)
}
logrus.Infof("Version: %s", Version)
logrus.Debugf("Conf: %#v", config)
var netw, addr string
switch {
case config.Addr != "":
netw = "tcp"
addr = config.Addr
case config.Unix != "":
netw = "unix"
addr = config.Unix
default:
panic("no address given")
}
netListener, err := net.Listen(netw, addr)
if err != nil {
logrus.Fatal(err)
}
httpServer := fasthttp.Server{
Logger: logrus.StandardLogger(),
GetOnly: true,
}
logrus.Infof("Version: %s", Version)
logrus.Debugf("Addr: %s+%s", netw, addr)
logrus.Debugf("Conf: %#v", config)
err = httpServer.Serve(netListener)
if err != nil {
logrus.Fatal(err)
}
}
+1
View File
@@ -6,4 +6,5 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.9.0
github.com/valyala/fasthttp v1.31.0
)