forked from aliyun/aliyun-log-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.go
52 lines (46 loc) · 972 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sls
import (
"fmt"
"net/http"
"strconv"
"strings"
)
func BoolToInt64(b bool) int64 {
if b {
return 1
}
return 0
}
func BoolPtrToStringNum(b *bool) string {
if b == nil {
return ""
}
if *b {
return "1"
}
return "0"
}
func Int64PtrToString(i *int64) string {
if i == nil {
return ""
}
return strconv.FormatInt(*i, 10)
}
func ParseHeaderInt(r *http.Response, headerName string) (int, error) {
values := r.Header[headerName]
if len(values) > 0 {
value, err := strconv.Atoi(values[0])
if err != nil {
return -1, fmt.Errorf("can't parse '%s' header: %v", strings.ToLower(headerName), err)
}
return value, nil
}
return -1, fmt.Errorf("can't find '%s' header", strings.ToLower(headerName))
}
func parseHeaderString(header http.Header, headerName string) (string, error) {
v, ok := header[headerName]
if !ok || len(v) == 0 {
return "", fmt.Errorf("can't find '%s' header", strings.ToLower(headerName))
}
return v[0], nil
}