mirror of
https://github.com/h44z/wg-portal.git
synced 2025-11-09 10:36:17 +00:00
chore: replace logrus with standard lib log/slog
This commit is contained in:
@@ -3,9 +3,9 @@ package domain
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const CtxUserInfo = "userInfo"
|
||||
@@ -95,7 +95,10 @@ func ValidateUserAccessRights(ctx context.Context, requiredUser UserIdentifier)
|
||||
return nil // User can access own data
|
||||
}
|
||||
|
||||
logrus.Warnf("insufficient permissions for %s (want %s), stack: %s", sessionUser.Id, requiredUser, GetStackTrace())
|
||||
slog.Warn("insufficient permissions",
|
||||
"user", sessionUser.Id,
|
||||
"requiredUser", requiredUser,
|
||||
"stack", GetStackTrace())
|
||||
return ErrNoPermission
|
||||
}
|
||||
|
||||
@@ -107,6 +110,8 @@ func ValidateAdminAccessRights(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
logrus.Warnf("insufficient admin permissions for %s, stack: %s", sessionUser.Id, GetStackTrace())
|
||||
slog.Warn("insufficient admin permissions",
|
||||
"user", sessionUser.Id,
|
||||
"stack", GetStackTrace())
|
||||
return ErrNoPermission
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math"
|
||||
"net"
|
||||
"regexp"
|
||||
@@ -9,8 +10,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/h44z/wg-portal/internal"
|
||||
)
|
||||
|
||||
@@ -166,18 +165,22 @@ func (i *Interface) GetRoutingTable() int {
|
||||
numberStr := strings.ReplaceAll(routingTableStr, "0x", "")
|
||||
routingTable, err := strconv.ParseUint(numberStr, 16, 64)
|
||||
if err != nil {
|
||||
logrus.Errorf("invalid hex routing table %s: %v", routingTableStr, err)
|
||||
slog.Error("failed to parse routing table number", "table", routingTableStr, "error", err)
|
||||
return -1
|
||||
}
|
||||
if routingTable > math.MaxInt32 {
|
||||
logrus.Errorf("invalid routing table %s, too big", routingTableStr)
|
||||
slog.Error("routing table number too large", "table", routingTable, "max", math.MaxInt32)
|
||||
return -1
|
||||
}
|
||||
return int(routingTable)
|
||||
default:
|
||||
routingTable, err := strconv.Atoi(routingTableStr)
|
||||
if err != nil {
|
||||
logrus.Errorf("invalid routing table %s: %v", routingTableStr, err)
|
||||
slog.Error("failed to parse routing table number", "table", routingTableStr, "error", err)
|
||||
return -1
|
||||
}
|
||||
if routingTable > math.MaxInt32 {
|
||||
slog.Error("routing table number too large", "table", routingTable, "max", math.MaxInt32)
|
||||
return -1
|
||||
}
|
||||
return routingTable
|
||||
|
||||
Reference in New Issue
Block a user