Move config to separate package

This commit is contained in:
Igor Chubin 2022-11-29 21:38:39 +01:00
parent f27bf2d5b3
commit 7b8c6665e8
2 changed files with 12 additions and 9 deletions

View file

@ -9,6 +9,8 @@ import (
"net" "net"
"net/http" "net/http"
"time" "time"
"github.com/chubin/wttr.in/internal/config"
) )
const uplinkSrvAddr = "127.0.0.1:9002" 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) { func serveHTTPS(mux *http.ServeMux, port int, logFile io.Writer, errs chan<- error) {
tlsConfig := &tls.Config{ tlsConfig := &tls.Config{
// CipherSuites: []uint16{ // CipherSuites: []uint16{
// tls.TLS_CHACHA20_POLY1305_SHA256, // tls.TLS_CHACHA20_POLY1305_SHA256,
// tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_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, TLSConfig: tlsConfig,
Handler: mux, Handler: mux,
} }
errs <- srv.ListenAndServeTLS(Conf.Server.TLSCertFile, Conf.Server.TLSKeyFile) errs <- srv.ListenAndServeTLS(config.Conf.Server.TLSCertFile, config.Conf.Server.TLSKeyFile)
} }
func main() { func main() {
@ -93,8 +96,8 @@ func main() {
// logger is optimized requests logger. // logger is optimized requests logger.
logger *RequestLogger = NewRequestLogger( logger *RequestLogger = NewRequestLogger(
Conf.Logging.AccessLog, config.Conf.Logging.AccessLog,
time.Duration(Conf.Logging.Interval)*time.Second) time.Duration(config.Conf.Logging.Interval)*time.Second)
rp *RequestProcessor rp *RequestProcessor
@ -105,7 +108,7 @@ func main() {
numberOfServers int numberOfServers int
errorsLog *LogSuppressor = NewLogSuppressor( errorsLog *LogSuppressor = NewLogSuppressor(
Conf.Logging.ErrorsLog, config.Conf.Logging.ErrorsLog,
[]string{ []string{
"error reading preface from client", "error reading preface from client",
"TLS handshake error from", "TLS handshake error from",
@ -149,12 +152,12 @@ func main() {
w.Write(response.Body) w.Write(response.Body)
}) })
if Conf.Server.PortHTTP != 0 { if config.Conf.Server.PortHTTP != 0 {
go serveHTTP(mux, Conf.Server.PortHTTP, errorsLog, errs) go serveHTTP(mux, config.Conf.Server.PortHTTP, errorsLog, errs)
numberOfServers++ numberOfServers++
} }
if Conf.Server.PortHTTPS != 0 { if config.Conf.Server.PortHTTPS != 0 {
go serveHTTPS(mux, Conf.Server.PortHTTPS, errorsLog, errs) go serveHTTPS(mux, config.Conf.Server.PortHTTPS, errorsLog, errs)
numberOfServers++ numberOfServers++
} }
if numberOfServers == 0 { if numberOfServers == 0 {

View file

@ -1,4 +1,4 @@
package main package config
// Config of the program. // Config of the program.
type Config struct { type Config struct {