/
util.go
51 lines (45 loc) · 917 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package vitali
import (
"fmt"
"strings"
"runtime"
"hash/crc32"
)
func panicOnErr(res interface{}, e error) interface{} {
if e != nil {
panic(e)
}
return res
}
func errorCode(msg string) uint32 {
return crc32.ChecksumIEEE([]byte(msg))
}
func lineInfo(skip int) (where string) {
_, fn, ln, ok := runtime.Caller(skip)
if ok {
where = fmt.Sprintf("%s:%d", fn, ln)
}
return
}
func fullTrace(skip int, sep string) (trace string) {
for {
where := lineInfo(skip)
skip++
if where == "" {
return
} else if strings.HasSuffix(where, ":0") {
continue
}
trace = trace + sep + where
}
return
}
func Seq(begin int, total int, step int) (res []int) {
res = make([]int, total)
v := begin
for i:=0; i<total; i++ {
res[i] = v
v += step
}
return
}