feat(cli): option to set port

This commit is contained in:
William Hergès 2025-07-19 23:06:15 +02:00
parent e9e5325bf8
commit f009b61110
Signed by untrusted user who does not match committer: anhgelus
GPG key ID: 617773CACE89052C

16
main.go
View file

@ -23,17 +23,19 @@ var (
var ( var (
domain string domain string
configPath string configPath string
dev bool dev bool = false
generateToml bool generateToml bool
generateJson bool generateJson bool
port int = 80
) )
func init() { func init() {
flag.StringVar(&domain, "domain", "", "domain to use") flag.StringVar(&domain, "domain", "", "domain to use")
flag.StringVar(&configPath, "config", "", "config to use") flag.StringVar(&configPath, "config", "", "config to use")
flag.BoolVar(&dev, "dev", false, "dev mode enabled") flag.BoolVar(&dev, "dev", dev, "dev mode enabled")
flag.BoolVar(&generateJson, "generate-json-config", false, "generate a config example") flag.BoolVar(&generateJson, "generate-json-config", false, "generate a config example")
flag.BoolVar(&generateToml, "generate-toml-config", false, "generate a config example") flag.BoolVar(&generateToml, "generate-toml-config", false, "generate a config example")
flag.IntVar(&port, "port", port, "set the port to use")
} }
func main() { func main() {
@ -125,11 +127,15 @@ func main() {
http.Redirect(w, r, "/", http.StatusTemporaryRedirect) http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
} }
host := fmt.Sprintf(":%d", port)
if dev { if dev {
slog.Info("Starting on http://localhost:8000/") if port != 80 {
g.StartServer(":8000") g.StartServer(host)
} else {
g.StartServer(":8000")
}
} else { } else {
g.StartServer(":80") g.StartServer(host)
} }
} }