mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-12-13 15:19:03 +00:00
Add log file support
This commit is contained in:
22
util.go
22
util.go
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// https://programming.guide/go/formatting-byte-size-to-human-readable-format.html
|
||||
func FormatByteCount(b uint64) string {
|
||||
@@ -16,3 +19,20 @@ func FormatByteCount(b uint64) string {
|
||||
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
}
|
||||
|
||||
type Hooks struct {
|
||||
m sync.Mutex
|
||||
l []func()
|
||||
}
|
||||
|
||||
func (h *Hooks) Add(hook func()) {
|
||||
h.m.Lock()
|
||||
h.l = append(h.l, hook)
|
||||
h.m.Unlock()
|
||||
}
|
||||
|
||||
func (h *Hooks) Execute() {
|
||||
for _, hook := range h.l {
|
||||
hook()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user