mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-17 14:09:44 +02:00
refactor: fix lint errors; improve error handling
This commit is contained in:
@@ -17,16 +17,19 @@ type (
|
||||
} // @name AccessLoggerConfigBase
|
||||
ACLLoggerConfig struct {
|
||||
ConfigBase
|
||||
|
||||
LogAllowed bool `json:"log_allowed"`
|
||||
} // @name ACLLoggerConfig
|
||||
RequestLoggerConfig struct {
|
||||
ConfigBase
|
||||
|
||||
Format Format `json:"format" validate:"oneof=common combined json"`
|
||||
Filters Filters `json:"filters"`
|
||||
Fields Fields `json:"fields"`
|
||||
} // @name RequestLoggerConfig
|
||||
Config struct {
|
||||
ConfigBase
|
||||
|
||||
acl *ACLLoggerConfig
|
||||
req *RequestLoggerConfig
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ type (
|
||||
}
|
||||
|
||||
fileAccessLogger struct {
|
||||
RequestFormatter
|
||||
ACLLogFormatter
|
||||
|
||||
task *task.Task
|
||||
cfg *Config
|
||||
|
||||
@@ -41,9 +44,6 @@ type (
|
||||
errRateLimiter *rate.Limiter
|
||||
|
||||
logger zerolog.Logger
|
||||
|
||||
RequestFormatter
|
||||
ACLLogFormatter
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ func (m *MockFile) Len() int64 {
|
||||
|
||||
func (m *MockFile) Content() []byte {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
m.Seek(0, io.SeekStart)
|
||||
_, _ = m.Seek(0, io.SeekStart)
|
||||
_, _ = buf.ReadFrom(m.File)
|
||||
m.Seek(0, io.SeekStart)
|
||||
_, _ = m.Seek(0, io.SeekStart)
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
type Retention struct {
|
||||
Days uint64 `json:"days,omitempty"`
|
||||
Last uint64 `json:"last,omitempty"`
|
||||
KeepSize uint64 `json:"keep_size,omitempty"`
|
||||
Days int64 `json:"days,omitempty" validate:"min=0"`
|
||||
Last int64 `json:"last,omitempty" validate:"min=0"`
|
||||
KeepSize int64 `json:"keep_size,omitempty" validate:"min=0"`
|
||||
} // @name LogRetention
|
||||
|
||||
var (
|
||||
@@ -39,9 +39,9 @@ func (r *Retention) Parse(v string) (err error) {
|
||||
}
|
||||
switch split[0] {
|
||||
case "last":
|
||||
r.Last, err = strconv.ParseUint(split[1], 10, 64)
|
||||
r.Last, err = strconv.ParseInt(split[1], 10, 64)
|
||||
default: // <N> days|weeks|months
|
||||
n, err := strconv.ParseUint(split[0], 10, 64)
|
||||
n, err := strconv.ParseInt(split[0], 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func rotateLogFileByPolicy(file supportRotate, config *Retention, result *Rotate
|
||||
|
||||
switch {
|
||||
case config.Last > 0:
|
||||
shouldStop = func() bool { return result.NumLinesKeep-result.NumLinesInvalid == int(config.Last) }
|
||||
shouldStop = func() bool { return int64(result.NumLinesKeep-result.NumLinesInvalid) == config.Last }
|
||||
// not needed to parse time for last N lines
|
||||
case config.Days > 0:
|
||||
cutoff := mockable.TimeNow().AddDate(0, 0, -int(config.Days)+1)
|
||||
@@ -227,7 +227,7 @@ func rotateLogFileBySize(file supportRotate, config *Retention, result *RotateRe
|
||||
|
||||
result.OriginalSize = fileSize
|
||||
|
||||
keepSize := int64(config.KeepSize)
|
||||
keepSize := config.KeepSize
|
||||
if keepSize >= fileSize {
|
||||
result.NumBytesKeep = fileSize
|
||||
return false, nil
|
||||
|
||||
Reference in New Issue
Block a user