/
response.go
42 lines (37 loc) · 923 Bytes
/
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
package http
import (
"fmt"
"strings"
)
type Response struct {
StatusCode int
StatusMessage string
Body []byte
Header map[string][]string
}
func (R *Response) GetStatusCodeStr() string {
return fmt.Sprintf("%d", R.StatusCode)
}
func (R *Response) GetStatusMessage() string {
return R.StatusMessage
}
func (R *Response) GetBody() []byte {
return R.Body
}
func (R *Response) GetHeader() map[string][]string {
return R.Header
}
func (R *Response) GetAllFields() map[string]string {
headerValues := make(map[string]string)
// Adicionando os campos extras do cabeçalho (ExtraFields)
for fieldName, fieldValues := range R.Header {
if len(fieldValues) > 0 {
// Se houver múltiplos valores para o campo, concatenamos eles em uma única string
headerValues[fieldName] = strings.Join(fieldValues, "; ")
}
}
return headerValues
}
func NewResponse() *Response {
return &Response{}
}