2024-07-19 16:52:06 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
appName = "rngpotd"
|
2024-07-26 11:07:36 +03:00
|
|
|
appVersion = "0.0.2"
|
2024-07-19 16:52:06 +03:00
|
|
|
userAgent = appName + "/" + appVersion
|
2024-07-26 11:07:36 +03:00
|
|
|
serverAgent = "nginx/1.27.1"
|
2024-07-19 16:52:06 +03:00
|
|
|
|
2024-07-26 11:07:36 +03:00
|
|
|
minimumGoMaxProcs = 4
|
|
|
|
maximumGoMaxProcs = 8
|
2024-07-19 16:52:06 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
listenEndpoint string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&listenEndpoint, "listen", ":8888", "listen (\":port\", \"address:port\")")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gmp := runtime.GOMAXPROCS(0)
|
|
|
|
if gmp < minimumGoMaxProcs {
|
|
|
|
runtime.GOMAXPROCS(minimumGoMaxProcs)
|
2024-07-26 11:07:36 +03:00
|
|
|
} else if gmp > maximumGoMaxProcs {
|
2024-07-19 16:52:06 +03:00
|
|
|
runtime.GOMAXPROCS(maximumGoMaxProcs)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetFlags(log.Flags() | log.Lmicroseconds)
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
log.Printf("%s: starting\n", userAgent)
|
|
|
|
|
|
|
|
app := initFiberApp()
|
2024-07-26 11:07:36 +03:00
|
|
|
if app == nil {
|
|
|
|
log.Fatal("failed to initialize rngpotd")
|
|
|
|
}
|
2024-07-19 16:52:06 +03:00
|
|
|
|
|
|
|
log.Printf("%s: ready\n", userAgent)
|
|
|
|
log.Printf("%s: going to listen %q\n", userAgent, listenEndpoint)
|
|
|
|
if err := app.Listen(listenEndpoint); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|