From 5bb0c4f1fe0bc759525f0c777283bdc5ecda2bd6 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sat, 19 Nov 2022 19:34:11 +0100 Subject: [PATCH] Move server config to Config struct --- cmd/config.go | 17 +++++++++++++++++ cmd/log.go | 1 + cmd/srv.go | 3 +-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 9aab0d0..03ee9a1 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -3,6 +3,7 @@ package main // Config of the program. type Config struct { Logging + Server } // Logging configuration. @@ -15,10 +16,26 @@ type Logging struct { 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. var Conf = Config{ Logging{ AccessLog: "/wttr.in/log/access.log", Interval: 300, }, + Server{ + PortHTTP: 8083, + PortHTTPS: 0, + }, } diff --git a/cmd/log.go b/cmd/log.go index a832c47..7385206 100644 --- a/cmd/log.go +++ b/cmd/log.go @@ -95,6 +95,7 @@ func (rl *RequestLogger) flush() error { return nil } +// String returns string representation of logEntry. func (e *logEntry) String() string { return fmt.Sprintf( "%s %s %s %s", diff --git a/cmd/srv.go b/cmd/srv.go index 94e41b8..d0b2eed 100644 --- a/cmd/srv.go +++ b/cmd/srv.go @@ -11,7 +11,6 @@ import ( lru "github.com/hashicorp/golang-lru" ) -const serverPort = 8083 const uplinkSrvAddr = "127.0.0.1:9002" const uplinkTimeout = 30 const prefetchInterval = 300 @@ -90,5 +89,5 @@ func main() { w.Write(response.Body) }) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", serverPort), nil)) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", Conf.Server.PortHTTP), nil)) }