diff --git a/.golangci.yml b/.golangci.yml index 549ef2f..6912df0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,8 @@ linters: - gocritic # Complains about main() lengths, which isn't an issue. - funlen + # Magic numbers might be everywhere. Disabled for now. + - gomnd linters-settings: lll: line-length: 420 diff --git a/internal/httpserver/checkallowedips.go b/internal/httpserver/checkallowedips.go index 169be3b..927a594 100644 --- a/internal/httpserver/checkallowedips.go +++ b/internal/httpserver/checkallowedips.go @@ -27,7 +27,9 @@ func checkAllowedIPs() echo.MiddlewareFunc { // into comparable things. // If IP address was specified without network mask - assume /32. var subnets []*net.IPNet + allowedIPs := configuration.Cfg.GetAllowedIPs() + for _, ip := range allowedIPs { ipToParse := ip if !strings.Contains(ip, "/") { @@ -46,7 +48,9 @@ func checkAllowedIPs() echo.MiddlewareFunc { // Check if requester's IP address are within allowed IP // subnets. ipToCheck := net.ParseIP(ec.RealIP()) + var allowed bool + for _, subnet := range subnets { if subnet.Contains(ipToCheck) { allowed = true diff --git a/internal/httpserver/requestlogger.go b/internal/httpserver/requestlogger.go index 7f8e684..a227aaa 100644 --- a/internal/httpserver/requestlogger.go +++ b/internal/httpserver/requestlogger.go @@ -2,12 +2,19 @@ package httpserver import ( // other + + "time" + "github.com/labstack/echo" ) func requestLogger() echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return func(ec echo.Context) error { + startTime := time.Now() + + err := next(ec) + log.Info(). Str("From", ec.RealIP()). Str("To", ec.Request().Host). @@ -15,10 +22,10 @@ func requestLogger() echo.MiddlewareFunc { Str("Path", ec.Request().URL.Path). Int64("Length", ec.Request().ContentLength). Str("UA", ec.Request().UserAgent()). + TimeDiff("TimeMS", time.Now(), startTime). Msg("HTTP request") - _ = next(ec) - return nil + return err } } }