Add more settings, cleanup code and add documentation

This commit is contained in:
Pablu23
2024-11-06 16:52:28 +01:00
parent a98b68177c
commit c0b711a992
4 changed files with 134 additions and 56 deletions

View File

@@ -57,10 +57,10 @@ func main() {
Handler: pipeline(mux),
}
if config.Server.CertFile != "" && config.Server.KeyFile != "" {
if config.Server.Ssl.Enabled {
server.TLSConfig = &tls.Config{
GetCertificate: func(chi *tls.ClientHelloInfo) (*tls.Certificate, error) {
cert, err := tls.LoadX509KeyPair(config.Server.CertFile, config.Server.KeyFile)
cert, err := tls.LoadX509KeyPair(config.Server.Ssl.CertFile, config.Server.Ssl.KeyFile)
if err != nil {
return nil, err
}
@@ -68,9 +68,9 @@ func main() {
},
}
log.Info().Int("port", config.Server.Port).Str("cert", config.Server.CertFile).Str("key", config.Server.KeyFile).Msg("Starting server")
log.Info().Int("port", config.Server.Port).Str("cert", config.Server.Ssl.CertFile).Str("key", config.Server.Ssl.KeyFile).Msg("Starting server")
err := server.ListenAndServeTLS("", "")
log.Fatal().Err(err).Str("cert", config.Server.CertFile).Str("key", config.Server.KeyFile).Int("port", config.Server.Port).Msg("Could not start server")
log.Fatal().Err(err).Str("cert", config.Server.Ssl.CertFile).Str("key", config.Server.Ssl.KeyFile).Int("port", config.Server.Port).Msg("Could not start server")
} else {
log.Info().Int("port", config.Server.Port).Msg("Starting server")
err := server.ListenAndServe()
@@ -111,19 +111,21 @@ func setupLogging(config *domainrouter.Config) {
}
zerolog.SetGlobalLevel(logLevel)
log.Info().Str("level", config.Logging.Level).Msg("Set logging level")
if config.Logging.Pretty {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
if config.Logging.Path != "" {
if config.Logging.File.Enabled {
var console io.Writer = os.Stderr
if config.Logging.Pretty {
console = zerolog.ConsoleWriter{Out: os.Stderr}
}
log.Logger = log.Output(zerolog.MultiLevelWriter(console, &lumberjack.Logger{
Filename: config.Logging.Path,
MaxAge: 14,
MaxBackups: 10,
Filename: config.Logging.File.Path,
MaxAge: config.Logging.File.MaxAge,
MaxBackups: config.Logging.File.MaxBackups,
}))
}
}