forked from sanity-io/client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
41 lines (36 loc) · 813 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
package sanity
import (
"encoding/json"
"fmt"
"net/http"
)
func isStatusCodeRetriable(code int) bool {
switch code {
case http.StatusServiceUnavailable, http.StatusGatewayTimeout, http.StatusRequestTimeout:
return true
default:
return false
}
}
func isMethodRetriable(method string) bool {
switch method {
case http.MethodGet, http.MethodHead, http.MethodDelete, http.MethodOptions:
return true
default:
return false
}
}
func marshalJSON(val interface{}) (*json.RawMessage, error) {
switch val := val.(type) {
case *json.RawMessage:
return val, nil
case []byte:
return (*json.RawMessage)(&val), nil
default:
b, err := json.Marshal(val)
if err != nil {
return nil, fmt.Errorf("marshaling value of type %T to JSON: %w", val, err)
}
return (*json.RawMessage)(&b), nil
}
}