Linting fixes and fixed HTTP requests logger.
This commit is contained in:
parent
bbb68c48a1
commit
2e07cb9726
@ -10,6 +10,8 @@ linters:
|
|||||||
- gocritic
|
- gocritic
|
||||||
# Complains about main() lengths, which isn't an issue.
|
# Complains about main() lengths, which isn't an issue.
|
||||||
- funlen
|
- funlen
|
||||||
|
# Magic numbers might be everywhere. Disabled for now.
|
||||||
|
- gomnd
|
||||||
linters-settings:
|
linters-settings:
|
||||||
lll:
|
lll:
|
||||||
line-length: 420
|
line-length: 420
|
||||||
|
@ -27,7 +27,9 @@ func checkAllowedIPs() echo.MiddlewareFunc {
|
|||||||
// into comparable things.
|
// into comparable things.
|
||||||
// If IP address was specified without network mask - assume /32.
|
// If IP address was specified without network mask - assume /32.
|
||||||
var subnets []*net.IPNet
|
var subnets []*net.IPNet
|
||||||
|
|
||||||
allowedIPs := configuration.Cfg.GetAllowedIPs()
|
allowedIPs := configuration.Cfg.GetAllowedIPs()
|
||||||
|
|
||||||
for _, ip := range allowedIPs {
|
for _, ip := range allowedIPs {
|
||||||
ipToParse := ip
|
ipToParse := ip
|
||||||
if !strings.Contains(ip, "/") {
|
if !strings.Contains(ip, "/") {
|
||||||
@ -46,7 +48,9 @@ func checkAllowedIPs() echo.MiddlewareFunc {
|
|||||||
// Check if requester's IP address are within allowed IP
|
// Check if requester's IP address are within allowed IP
|
||||||
// subnets.
|
// subnets.
|
||||||
ipToCheck := net.ParseIP(ec.RealIP())
|
ipToCheck := net.ParseIP(ec.RealIP())
|
||||||
|
|
||||||
var allowed bool
|
var allowed bool
|
||||||
|
|
||||||
for _, subnet := range subnets {
|
for _, subnet := range subnets {
|
||||||
if subnet.Contains(ipToCheck) {
|
if subnet.Contains(ipToCheck) {
|
||||||
allowed = true
|
allowed = true
|
||||||
|
@ -2,12 +2,19 @@ package httpserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
// other
|
// other
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func requestLogger() echo.MiddlewareFunc {
|
func requestLogger() echo.MiddlewareFunc {
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(ec echo.Context) error {
|
return func(ec echo.Context) error {
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
|
err := next(ec)
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("From", ec.RealIP()).
|
Str("From", ec.RealIP()).
|
||||||
Str("To", ec.Request().Host).
|
Str("To", ec.Request().Host).
|
||||||
@ -15,10 +22,10 @@ func requestLogger() echo.MiddlewareFunc {
|
|||||||
Str("Path", ec.Request().URL.Path).
|
Str("Path", ec.Request().URL.Path).
|
||||||
Int64("Length", ec.Request().ContentLength).
|
Int64("Length", ec.Request().ContentLength).
|
||||||
Str("UA", ec.Request().UserAgent()).
|
Str("UA", ec.Request().UserAgent()).
|
||||||
|
TimeDiff("TimeMS", time.Now(), startTime).
|
||||||
Msg("HTTP request")
|
Msg("HTTP request")
|
||||||
|
|
||||||
_ = next(ec)
|
return err
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user