-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbody.go
56 lines (43 loc) · 1.02 KB
/
body.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
53
54
55
56
package main
import (
"encoding/json"
"net/http"
"strings"
"github.com/ninlil/butler/log"
)
type bodyStructData struct {
Data string `json:"data"`
}
type bodyStructArgs struct {
Body *bodyStructData `from:"body"`
}
type bodyByteArgs struct {
Body []byte `from:"body"`
}
type bodyStringArgs struct {
Body string `from:"body"`
}
type bodyStringsArgs struct {
Body []string `from:"body"`
}
type bodyMapArgs struct {
Body map[string]interface{} `from:"body"`
}
func bodyStruct(r *http.Request, args *bodyStructArgs) string {
log.AddRequestFields(r, "method", "bodyStruct")
return args.Body.Data
}
func bodyBytes(args *bodyByteArgs) string {
return string(args.Body)
}
func bodyString(args *bodyStringArgs) string {
return args.Body
}
func bodyStrings(args *bodyStringsArgs) string {
return strings.Join(args.Body, ", ")
}
func bodyMap(r *http.Request, args *bodyMapArgs) []byte {
log.AddRequestFields(r, "method", "bodyMap", "mapSize", len(args.Body))
data, _ := json.MarshalIndent(args.Body, "", " ")
return data
}