-
Notifications
You must be signed in to change notification settings - Fork 2
/
response.go
67 lines (52 loc) · 1.09 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
65
66
67
package response
import (
"net/http"
)
type (
DataResponse struct {
data any
statusCode int
header http.Header
}
)
func NewDataResponse(code int, data any) *DataResponse {
return &DataResponse{
data: data,
statusCode: code,
header: make(http.Header),
}
}
func (d *DataResponse) Header() http.Header {
return d.header
}
func (d *DataResponse) Data() any {
return d.data
}
func (d *DataResponse) StatusCode() int {
return d.statusCode
}
func (d *DataResponse) HeaderValues(key string) []string {
return d.header.Values(key)
}
func (d *DataResponse) HeaderLine(key string) string {
return d.header.Get(key)
}
func (d *DataResponse) WithHeader(key, value string) *DataResponse {
d.header.Add(key, value)
return d
}
func (d *DataResponse) WithHeaders(headers http.Header) *DataResponse {
for k, values := range headers {
for _, v := range values {
d.header.Add(k, v)
}
}
return d
}
func (d *DataResponse) HasHeader(key string) bool {
return d.header.Get(key) != ""
}
func (d *DataResponse) WithData(data any) *DataResponse {
d.data = data
return d
}