-
Notifications
You must be signed in to change notification settings - Fork 312
/
supportFunc.go
49 lines (44 loc) · 914 Bytes
/
supportFunc.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
package main
import (
"crypto/rand"
"fmt"
"strconv"
"strings"
)
//Default streams signals
const (
SignalStreamRestart = iota ///< Y Restart
SignalStreamStop
SignalStreamClient
)
//generateUUID function make random uuid for clients and stream
func generateUUID() (string, error) {
b := make([]byte, 16)
_, err := rand.Read(b)
if err != nil {
return "", err
}
return fmt.Sprintf("%X-%X-%X-%X-%X", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]), nil
}
//stringToInt convert string to int if err to zero
func stringToInt(val string) int {
i, err := strconv.Atoi(val)
if err != nil {
return 0
}
return i
}
//stringInBetween fin char to char sub string
func stringInBetween(str string, start string, end string) (result string) {
s := strings.Index(str, start)
if s == -1 {
return
}
str = str[s+len(start):]
e := strings.Index(str, end)
if e == -1 {
return
}
str = str[:e]
return str
}