X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/a6216dd89252fa01dc176f98f1e4ecfd3f637566..a55350daaf83498b7a237c027ad0dd2377f06fee:/cmd/mobius-hotline-server/main.go diff --git a/cmd/mobius-hotline-server/main.go b/cmd/mobius-hotline-server/main.go index c027d18..c34dc71 100644 --- a/cmd/mobius-hotline-server/main.go +++ b/cmd/mobius-hotline-server/main.go @@ -28,6 +28,12 @@ var logLevels = map[string]slog.Level{ "error": slog.LevelError, } +var ( + version = "dev" + commit = "none" + date = "unknown" +) + func main() { ctx, cancel := context.WithCancel(context.Background()) @@ -50,7 +56,7 @@ func main() { basePort := flag.Int("bind", defaultPort, "Base Hotline server port. File transfer port is base port + 1.") statsPort := flag.String("stats-port", "", "Enable stats HTTP endpoint on address and port") configDir := flag.String("config", defaultConfigPath(), "Path to config root") - version := flag.Bool("version", false, "print version and exit") + printVersion := flag.Bool("version", false, "print version and exit") logLevel := flag.String("log-level", "info", "Log level") logFile := flag.String("log-file", "", "Path to log file") @@ -58,8 +64,8 @@ func main() { flag.Parse() - if *version { - fmt.Printf("v%s\n", hotline.VERSION) + if *printVersion { + fmt.Printf("mobius-hotline-server %s, commit %s, built at %s", version, commit, date) os.Exit(0) } @@ -93,7 +99,7 @@ func main() { } if _, err := os.Stat(*configDir); os.IsNotExist(err) { - slogger.Error(fmt.Sprintf("Configuration directory not found. Correct the path or re-run with -init to generate initial config.")) + slogger.Error("Configuration directory not found. Correct the path or re-run with -init to generate initial config.") os.Exit(1) } @@ -116,6 +122,12 @@ func main() { }(srv) } + slogger.Info("Hotline server started", + "version", version, + "API port", fmt.Sprintf("%s:%v", *netInterface, *basePort), + "Transfer port", fmt.Sprintf("%s:%v", *netInterface, *basePort+1), + ) + // Serve Hotline requests until program exit log.Fatal(srv.ListenAndServe(ctx, cancel)) } @@ -133,7 +145,9 @@ func (sh *statHandler) RenderStats(w http.ResponseWriter, _ *http.Request) { _, _ = io.WriteString(w, string(u)) } -func defaultConfigPath() (cfgPath string) { +func defaultConfigPath() string { + var cfgPath string + switch runtime.GOOS { case "windows": cfgPath = "config/"