From d26d8e3ca83a67727aae50c98f5c95ce88d7501b Mon Sep 17 00:00:00 2001 From: Jan Gottschick Date: Mon, 23 Sep 2024 17:50:36 +0200 Subject: [PATCH] * fix PORT bug --- templates/Dockerfile.tmpl | 1 + templates/core/config.go.tmpl | 11 +++++++---- templates/main.go.tmpl | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/templates/Dockerfile.tmpl b/templates/Dockerfile.tmpl index 2b4de13..0cea7c0 100644 --- a/templates/Dockerfile.tmpl +++ b/templates/Dockerfile.tmpl @@ -38,3 +38,4 @@ USER appuser:appuser EXPOSE {{ .Port }} # Run the app binary CMD ["/go/bin/app"] +# CMD ["/go/bin/app","-d"] diff --git a/templates/core/config.go.tmpl b/templates/core/config.go.tmpl index e899a90..c13fd8e 100644 --- a/templates/core/config.go.tmpl +++ b/templates/core/config.go.tmpl @@ -19,7 +19,7 @@ type Config struct { Sid string `ignored:"true"` Name string `default:"{{.ModuleName}}"` Title string - Port string `default:"8080"` + PortNb string `default:"8080"` // Port is a reserved name in k8s ApiKeys []string `default:"" split_words:"true"` AuthorizationHeader string `default:"" split_words:"true"` SessionKey string `default:"" split_words:"true"` @@ -55,12 +55,15 @@ func init() { AppConfig.Sid = sid.String() // parse command line arguments - flag.StringVar(&AppConfig.Port, "port", AppConfig.Port, "AppConfig.Port to listen by the server") - flag.StringVar(&AppConfig.Port, "p", AppConfig.Port, "AppConfig.Port to listen by the server") + flag.StringVar(&AppConfig.PortNb, "port", AppConfig.PortNb, "AppConfig.PortNb to listen by the server") + flag.StringVar(&AppConfig.PortNb, "p", AppConfig.PortNb, "AppConfig.PortNb to listen by the server") flag.StringVar(&AppConfig.Name, "name", AppConfig.Name, "Name of the service") flag.StringVar(&AppConfig.Name, "n", AppConfig.Name, "Name of the service") flag.BoolVar(&AppConfig.Debug, "d", AppConfig.Debug, "enable debugging level for logging") flag.BoolVar(&AppConfig.Version, "V", AppConfig.Version, "print version") + flag.Parse() + + log.Debug().Str("name", AppConfig.Name).Any("environment", os.Environ()).Msg("Got environment") if AppConfig.Name == "" { AppConfig.Name = service @@ -97,6 +100,6 @@ func init() { AppConfig.SessionKey = AppConfig.Name } - log.Debug().Str("name", AppConfig.Name).Any("environment", AppConfig).Msg("Got environment") + log.Debug().Str("name", AppConfig.Name).Any("config", AppConfig).Msg("Got configuration") AppInfo.Name = AppConfig.Name } diff --git a/templates/main.go.tmpl b/templates/main.go.tmpl index b14403e..02ddb1f 100644 --- a/templates/main.go.tmpl +++ b/templates/main.go.tmpl @@ -29,7 +29,7 @@ var embeddedFS embed.FS func main() { // ToDo: Add basic command line options as _-n_/_-name_ and _-d_/_-debug_ using flags - log.Info().Msg("Starting service") + log.Info().Str("port", core.AppConfig.PortNb).Msg("Starting service") // init Opentelemetry if core.AppConfig.Tracing { @@ -74,8 +74,8 @@ func main() { if core.AppConfig.CertPem != "" && core.AppConfig.KeyPem != "" { - e.Logger.Fatal(e.StartTLS(":" + core.AppConfig.Port, []byte(core.AppConfig.CertPem), []byte(core.AppConfig.KeyPem))) + e.Logger.Fatal(e.StartTLS(":" + core.AppConfig.PortNb, []byte(core.AppConfig.CertPem), []byte(core.AppConfig.KeyPem))) } else { - e.Logger.Fatal(e.Start(":" + core.AppConfig.Port)) + e.Logger.Fatal(e.Start(":" + core.AppConfig.PortNb)) } }