-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
43 lines (35 loc) · 804 Bytes
/
utils.go
File metadata and controls
43 lines (35 loc) · 804 Bytes
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
package utils
import (
"fmt"
"log"
"github.com/474420502/random"
)
func TryPanic(do func()) (err error) {
defer func() {
err = recover().(error)
}()
do()
return nil
}
var basechars []byte = []byte("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789")
func Rangdom(s, e int, seeds ...interface{}) []byte {
var r *random.Random
if len(seeds) > 0 {
r = seeds[0].(*random.Random)
} else {
r = random.NewNoLog()
}
size := len(basechars)
msize := r.Intn(e+s) + s
var result []byte = make([]byte, msize)
for i := 0; i < msize; i++ {
result[i] = basechars[r.Intn(size)]
}
return result
}
func Expect(exceptValid string, inputs ...any) {
result := fmt.Sprint(inputs...)
if result != exceptValid {
log.Panicf("inputs != except: %s != %s", result, exceptValid)
}
}