split into packages

This commit is contained in:
ston1th 2018-02-09 22:38:47 +01:00
commit c5d41b0965
26 changed files with 328 additions and 449 deletions

36
pkg/util/helper.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"fmt"
"strconv"
"time"
)
const timeFmt = "2006-01-02 15:04:05"
func now() string {
return time.Now().Format(timeFmt)
}
func since(t time.Time) string {
s := time.Since(t)
u := uint64(s)
if u <= 0 {
return "0s"
}
str := s.String()
switch {
case u >= uint64(time.Second):
f, _ := strconv.ParseFloat(str[:len(str)-1], 64)
return fmt.Sprintf("%.fs", f)
case u < uint64(time.Microsecond):
f, _ := strconv.ParseFloat(str[:len(str)-2], 64)
return fmt.Sprintf("%.fns", f)
case u < uint64(time.Millisecond):
f, _ := strconv.ParseFloat(str[:len(str)-3], 64)
return fmt.Sprintf("%.fµs", f)
default:
f, _ := strconv.ParseFloat(str[:len(str)-2], 64)
return fmt.Sprintf("%.fms", f)
}
}