refactor: code refactor and improved context and error handling

This commit is contained in:
yusing
2025-05-24 10:02:24 +08:00
parent 1f1ae38e4d
commit 5b7c392297
31 changed files with 116 additions and 98 deletions

View File

@@ -83,6 +83,9 @@ func NewAccessLogger(parent task.Parent, cfg AnyConfig) (*AccessLogger, error) {
if err != nil {
return nil, err
}
if io == nil {
return nil, nil //nolint:nilnil
}
return NewAccessLoggerWithIO(parent, io, cfg), nil
}
@@ -181,7 +184,7 @@ func (l *AccessLogger) LogError(req *http.Request, err error) {
func (l *AccessLogger) LogACL(info *maxmind.IPInfo, blocked bool) {
line := l.lineBufPool.Get()
defer l.lineBufPool.Put(line)
line = l.ACLFormatter.AppendACLLog(line, info, blocked)
line = l.AppendACLLog(line, info, blocked)
if line[len(line)-1] != '\n' {
line = append(line, '\n')
}
@@ -194,7 +197,7 @@ func (l *AccessLogger) ShouldRotate() bool {
func (l *AccessLogger) Rotate() (result *RotateResult, err error) {
if !l.ShouldRotate() {
return nil, nil
return nil, nil //nolint:nilnil
}
l.writer.Flush()