forked from appwrite/sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
36 lines (34 loc) · 740 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
package appwrite
import (
"fmt"
"reflect"
"strconv"
)
// ToString changes arg to string
func ToString(arg interface{}) string {
var tmp = reflect.Indirect(reflect.ValueOf(arg)).Interface()
switch v := tmp.(type) {
case int:
return strconv.Itoa(v)
case int8:
return strconv.FormatInt(int64(v), 10)
case int16:
return strconv.FormatInt(int64(v), 10)
case int32:
return strconv.FormatInt(int64(v), 10)
case int64:
return strconv.FormatInt(v, 10)
case string:
return v
case float32:
return strconv.FormatFloat(float64(v), 'f', -1, 32)
case float64:
return strconv.FormatFloat(v, 'f', -1, 64)
case fmt.Stringer:
return v.String()
case reflect.Value:
return ToString(v.Interface())
default:
return ""
}
}