From 7b8c6665e8da9a8dcd7050dbfda98cea068a318e Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Tue, 29 Nov 2022 21:38:39 +0100 Subject: [PATCH] Move config to separate package --- cmd/srv.go | 19 +++++++++++-------- {cmd => internal/config}/config.go | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) rename {cmd => internal/config}/config.go (98%) diff --git a/cmd/srv.go b/cmd/srv.go index e1d0955..0db5a9d 100644 --- a/cmd/srv.go +++ b/cmd/srv.go @@ -9,6 +9,8 @@ import ( "net" "net/http" "time" + + "github.com/chubin/wttr.in/internal/config" ) const uplinkSrvAddr = "127.0.0.1:9002" @@ -67,6 +69,7 @@ func serveHTTP(mux *http.ServeMux, port int, logFile io.Writer, errs chan<- erro func serveHTTPS(mux *http.ServeMux, port int, logFile io.Writer, errs chan<- error) { tlsConfig := &tls.Config{ + // CipherSuites: []uint16{ // tls.TLS_CHACHA20_POLY1305_SHA256, // tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, @@ -83,7 +86,7 @@ func serveHTTPS(mux *http.ServeMux, port int, logFile io.Writer, errs chan<- err TLSConfig: tlsConfig, Handler: mux, } - errs <- srv.ListenAndServeTLS(Conf.Server.TLSCertFile, Conf.Server.TLSKeyFile) + errs <- srv.ListenAndServeTLS(config.Conf.Server.TLSCertFile, config.Conf.Server.TLSKeyFile) } func main() { @@ -93,8 +96,8 @@ func main() { // logger is optimized requests logger. logger *RequestLogger = NewRequestLogger( - Conf.Logging.AccessLog, - time.Duration(Conf.Logging.Interval)*time.Second) + config.Conf.Logging.AccessLog, + time.Duration(config.Conf.Logging.Interval)*time.Second) rp *RequestProcessor @@ -105,7 +108,7 @@ func main() { numberOfServers int errorsLog *LogSuppressor = NewLogSuppressor( - Conf.Logging.ErrorsLog, + config.Conf.Logging.ErrorsLog, []string{ "error reading preface from client", "TLS handshake error from", @@ -149,12 +152,12 @@ func main() { w.Write(response.Body) }) - if Conf.Server.PortHTTP != 0 { - go serveHTTP(mux, Conf.Server.PortHTTP, errorsLog, errs) + if config.Conf.Server.PortHTTP != 0 { + go serveHTTP(mux, config.Conf.Server.PortHTTP, errorsLog, errs) numberOfServers++ } - if Conf.Server.PortHTTPS != 0 { - go serveHTTPS(mux, Conf.Server.PortHTTPS, errorsLog, errs) + if config.Conf.Server.PortHTTPS != 0 { + go serveHTTPS(mux, config.Conf.Server.PortHTTPS, errorsLog, errs) numberOfServers++ } if numberOfServers == 0 { diff --git a/cmd/config.go b/internal/config/config.go similarity index 98% rename from cmd/config.go rename to internal/config/config.go index bf6cf90..8ccd493 100644 --- a/cmd/config.go +++ b/internal/config/config.go @@ -1,4 +1,4 @@ -package main +package config // Config of the program. type Config struct {