Move server config to Config struct

This commit is contained in:
Igor Chubin 2022-11-19 19:34:11 +01:00
parent 7d801e3b4d
commit 5bb0c4f1fe
3 changed files with 19 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package main
// Config of the program. // Config of the program.
type Config struct { type Config struct {
Logging Logging
Server
} }
// Logging configuration. // Logging configuration.
@ -15,10 +16,26 @@ type Logging struct {
Interval int Interval int
} }
// Server configuration.
type Server struct {
// PortHTTP is port where HTTP server must listen.
// If 0, HTTP is disabled.
PortHTTP int
// PortHTTP is port where the HTTPS server must listen.
// If 0, HTTPS is disabled.
PortHTTPS int
}
// Conf contains the current configuration. // Conf contains the current configuration.
var Conf = Config{ var Conf = Config{
Logging{ Logging{
AccessLog: "/wttr.in/log/access.log", AccessLog: "/wttr.in/log/access.log",
Interval: 300, Interval: 300,
}, },
Server{
PortHTTP: 8083,
PortHTTPS: 0,
},
} }

View file

@ -95,6 +95,7 @@ func (rl *RequestLogger) flush() error {
return nil return nil
} }
// String returns string representation of logEntry.
func (e *logEntry) String() string { func (e *logEntry) String() string {
return fmt.Sprintf( return fmt.Sprintf(
"%s %s %s %s", "%s %s %s %s",

View file

@ -11,7 +11,6 @@ import (
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
) )
const serverPort = 8083
const uplinkSrvAddr = "127.0.0.1:9002" const uplinkSrvAddr = "127.0.0.1:9002"
const uplinkTimeout = 30 const uplinkTimeout = 30
const prefetchInterval = 300 const prefetchInterval = 300
@ -90,5 +89,5 @@ func main() {
w.Write(response.Body) w.Write(response.Body)
}) })
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", serverPort), nil)) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", Conf.Server.PortHTTP), nil))
} }