mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 03:58:45 +00:00
Move config to separate package
This commit is contained in:
parent
f27bf2d5b3
commit
7b8c6665e8
2 changed files with 12 additions and 9 deletions
19
cmd/srv.go
19
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 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package config
|
||||
|
||||
// Config of the program.
|
||||
type Config struct {
|
Loading…
Reference in a new issue