-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
48 lines (41 loc) · 882 Bytes
/
model.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
package xhttp
import "encoding/json"
const (
GET = "GET"
POST = "POST"
PUT = "PUT"
DELETE = "DELETE"
PATCH = "PATCH"
ResTypeJSON = "json"
ResTypeXML = "xml"
TypeJSON = "json"
TypeXML = "xml"
TypeFormData = "form-data"
TypeMultipartFormData = "multipart-form-data"
)
var (
_ReqContentTypeMap = map[string]string{
TypeJSON: "application/json",
TypeXML: "application/xml",
TypeFormData: "application/x-www-form-urlencoded",
TypeMultipartFormData: "multipart/form-data",
}
_ResTypeMap = map[string]string{
ResTypeJSON: "application/json",
ResTypeXML: "application/xml",
}
)
func ConvertToString(v any) (str string) {
if v == nil {
return ""
}
var (
bs []byte
err error
)
if bs, err = json.Marshal(v); err != nil {
return ""
}
str = string(bs)
return
}