finished tag implementation

This commit is contained in:
ston1th 2019-08-24 14:27:58 +02:00
commit c3076c328a
28 changed files with 396 additions and 296 deletions

47
pkg/log/scanlog.go Normal file
View file

@ -0,0 +1,47 @@
package log
import (
"fmt"
"git.giftfish.de/ston1th/docstore/pkg/core"
"sync"
)
const defaultSize = 500
type ScanLog struct {
// protects logs
sync.RWMutex
size int
logs []string
}
func NewScanLog(size int) *ScanLog {
if size <= 0 {
size = defaultSize
}
return &ScanLog{size: size}
}
func (l *ScanLog) Printf(f string, v ...interface{}) {
s := fmt.Sprintf(f, v...)
Println(s)
s = core.LogTime() + s
l.Lock()
logsLen := len(l.logs)
if logsLen < l.size {
l.logs = append(l.logs, s)
} else if logsLen == l.size {
l.logs = append(l.logs[1:], s)
}
l.Unlock()
}
func (l *ScanLog) Logs() (logs string) {
l.RLock()
for _, v := range l.logs {
logs += "\n" + v
}
l.RUnlock()
return
}