forked from deepch/go-onvif
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
38 lines (31 loc) · 773 Bytes
/
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
package onvif
import (
"encoding/json"
"strconv"
"strings"
)
var testDevice = Device{
XAddr: "http://192.168.1.75:5000/onvif/device_service",
}
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 interfaceToFloat64(src interface{}) float64 {
strNumber := interfaceToString(src)
number, _ := strconv.ParseFloat(strNumber, 64)
return number
}
func prettyJSON(src interface{}) string {
result, _ := json.MarshalIndent(&src, "", " ")
return string(result)
}