some lint fixes

This commit is contained in:
ston1th 2021-11-05 22:10:52 +01:00
commit 9f4fda3c8b
11 changed files with 36 additions and 40 deletions

View file

@ -14,12 +14,12 @@ var (
debug = false
)
func InitLogger(cfg core.Config) {
func InitLogger(cfg *core.Config) {
debug = cfg.Debug
if cfg.LogFile == "-" {
return
}
f, err := os.OpenFile(filepath.Join(cfg.DataDir, cfg.LogFile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0640)
f, err := os.OpenFile(filepath.Join(cfg.DataDir, cfg.LogFile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o640)
if err != nil {
stdlog.Fatal(err)
}

View file

@ -13,7 +13,7 @@ const defaultSize = 500
type ScanLog struct {
// protects logs
sync.RWMutex
mu sync.RWMutex
size int
logs []string
@ -30,20 +30,20 @@ func (l *ScanLog) Printf(f string, v ...interface{}) {
s := fmt.Sprintf(f, v...)
Println(s)
s = core.LogTime() + s
l.Lock()
l.mu.Lock()
llen := len(l.logs)
if llen < l.size {
l.logs = append(l.logs, s)
} else if llen == l.size {
l.logs = append(l.logs[1:], s)
}
l.Unlock()
l.mu.Unlock()
}
func (l *ScanLog) Logs() (logs string) {
l.RLock()
l.mu.RLock()
logs = reverseJoin(l.logs, "\n")
l.RUnlock()
l.mu.RUnlock()
return
}