forked from an/flokati
Rework of module system.
This commit is contained in:
parent
69e8ef85b1
commit
ae56ff904c
12 changed files with 219 additions and 199 deletions
21
util/util.go
21
util/util.go
|
@ -4,9 +4,25 @@ package util
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ToInt(v interface{}) int {
|
||||
switch v.(type) {
|
||||
case int:
|
||||
return v.(int)
|
||||
case float64:
|
||||
return int(v.(float64))
|
||||
case string:
|
||||
ret, _ := strconv.Atoi(v.(string))
|
||||
return ret
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func NumberToString(n int, sep rune) string {
|
||||
start := 0
|
||||
var buf bytes.Buffer
|
||||
|
@ -31,3 +47,8 @@ func NumberToString(n int, sep rune) string {
|
|||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func Random(min, max int) int {
|
||||
rand.Seed(time.Now().Unix())
|
||||
return rand.Intn(max-min) + min
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue