/
response.go
64 lines (52 loc) · 1.26 KB
/
response.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
57
58
59
60
61
62
63
64
package bifrost
import (
"context"
"net/http"
)
type ctxKeyVersion struct {
Name string
}
func (r *ctxKeyVersion) String() string {
return "context value " + r.Name
}
type ctxKeyResponse struct {
Name string
}
func (r *ctxKeyResponse) String() string {
return "context value " + r.Name
}
var (
CtxResponse = ctxKeyResponse{Name: "context Respond"}
CtxVersion = ctxKeyVersion{Name: "context version"}
)
type Meta struct {
Code string `json:"code,omitempty"`
Type string `json:"error_type,omitempty"`
Message string `json:"error_message,omitempty"`
}
type Version struct {
Label string `json:"label,omitempty"`
Number string `json:"number,omitempty"`
}
type Response struct {
Version interface{} `json:"version,omitempty"`
Meta interface{} `json:"meta,omitempty"`
Data interface{} `json:"data,omitempty"`
Pagination interface{} `json:"pagination,omitempty"`
}
func SemanticVersion(r *http.Request, label string, version string) {
*r = *r.WithContext(context.WithValue(r.Context(), CtxVersion, Version{
Label: label,
Number: version,
}))
}
type Pagination struct {
Limit int `json:"limit"`
NextCursor interface{} `json:"next_cursor"`
}
func (p Pagination) GetLimit() int {
if p.Limit < 1 {
return 10
}
return p.Limit
}