fix(lint): fix all linting errors
- Check BindEnv return values in config.go - Add bounds checks for int->int32/uint32 conversions to prevent overflow - Remove unused test helper functions
This commit is contained in:
@@ -4,6 +4,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
auditv1 "git.dcentral.systems/toolz/goplt/api/proto/generated/audit/v1"
|
||||
"git.dcentral.systems/toolz/goplt/pkg/registry"
|
||||
@@ -86,9 +87,17 @@ func (c *AuditClient) Query(ctx context.Context, filters *services.AuditLogFilte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
limit := filters.Limit
|
||||
if limit > math.MaxInt32 {
|
||||
limit = math.MaxInt32
|
||||
}
|
||||
offset := filters.Offset
|
||||
if offset > math.MaxInt32 {
|
||||
offset = math.MaxInt32
|
||||
}
|
||||
req := &auditv1.QueryRequest{
|
||||
Limit: int32(filters.Limit),
|
||||
Offset: int32(filters.Offset),
|
||||
Limit: int32(limit),
|
||||
Offset: int32(offset),
|
||||
}
|
||||
|
||||
if filters.UserID != nil {
|
||||
|
||||
@@ -100,9 +100,15 @@ func LoadConfig(env string) (config.ConfigProvider, error) {
|
||||
// e.g., DATABASE_DSN -> database.dsn, SERVER_PORT -> server.port
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
// Bind specific environment variables to config keys
|
||||
v.BindEnv("database.dsn", "DATABASE_DSN")
|
||||
v.BindEnv("registry.consul.address", "REGISTRY_CONSUL_ADDRESS")
|
||||
v.BindEnv("registry.type", "REGISTRY_TYPE")
|
||||
if err := v.BindEnv("database.dsn", "DATABASE_DSN"); err != nil {
|
||||
return nil, fmt.Errorf("failed to bind DATABASE_DSN: %w", err)
|
||||
}
|
||||
if err := v.BindEnv("registry.consul.address", "REGISTRY_CONSUL_ADDRESS"); err != nil {
|
||||
return nil, fmt.Errorf("failed to bind REGISTRY_CONSUL_ADDRESS: %w", err)
|
||||
}
|
||||
if err := v.BindEnv("registry.type", "REGISTRY_TYPE"); err != nil {
|
||||
return nil, fmt.Errorf("failed to bind REGISTRY_TYPE: %w", err)
|
||||
}
|
||||
|
||||
return NewViperConfig(v), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user