forked from quocson95/go-onvif
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
65 lines (53 loc) · 1.22 KB
/
utils.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package onvif
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
var testDevice = Device{
XAddr: "http://192.168.0.11/onvif/device_service",
User: "admin",
Password: "Admin123",
}
func interfaceToString(src interface{}) string {
str, _ := src.(string)
return str
}
func interfaceToBool(src interface{}) bool {
strBool := interfaceToString(src)
return strings.ToLower(strBool) == "true"
}
func interfaceToInt(src interface{}) int {
strNumber := interfaceToString(src)
number, _ := strconv.Atoi(strNumber)
return number
}
func prettyJSON(src interface{}) string {
result, _ := json.MarshalIndent(&src, "", " ")
return string(result)
}
func interfaceToFloat64(src interface{}) float64 {
strNumber := interfaceToString(src)
number, _ := strconv.ParseFloat(strNumber, 64)
return number
}
func intToString(src int) string {
strInt := strconv.Itoa(src)
return strInt
}
func float64ToString(src float64) string {
strFloat64 := fmt.Sprint(src)
return strFloat64
}
func boolToString(src bool) string {
if src {
return "true"
}
return "false"
}
// kiem tra co phai loi chung thuc hay khong
func CheckAuthorizedError(msg string) bool {
msg = strings.ToLower(msg)
return strings.Index(msg, "authorized") != -1
}