Linting fixes and fixed HTTP requests logger.
This commit is contained in:
parent
bbb68c48a1
commit
2e07cb9726
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user