forked from mccutchen/go-httpbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responses.go
81 lines (66 loc) · 1.86 KB
/
responses.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package httpbin
import (
"net/http"
"net/url"
)
const (
binaryContentType = "application/octet-stream"
htmlContentType = "text/html; charset=utf-8"
jsonContentType = "application/json; charset=utf-8"
textContentType = "text/plain; charset=utf-8"
)
type headersResponse struct {
Headers http.Header `json:"headers"`
}
type ipResponse struct {
Origin string `json:"origin"`
}
type userAgentResponse struct {
UserAgent string `json:"user-agent"`
}
// A generic response for any incoming request that should not contain a body
// (GET, HEAD, OPTIONS, etc).
type noBodyResponse struct {
Args url.Values `json:"args"`
Headers http.Header `json:"headers"`
Method string `json:"method"`
Origin string `json:"origin"`
URL string `json:"url"`
Deflated bool `json:"deflated,omitempty"`
Gzipped bool `json:"gzipped,omitempty"`
}
// A generic response for any incoming request that might contain a body (POST,
// PUT, PATCH, etc).
type bodyResponse struct {
Data string
JSON interface{}
}
type cookiesResponse map[string]string
type authResponse struct {
Authorized bool `json:"authorized"`
User string `json:"user"`
}
// An actual stream response body will be made up of one or more of these
// structs, encoded as JSON and separated by newlines
type streamResponse struct {
ID int `json:"id"`
Args url.Values `json:"args"`
Headers http.Header `json:"headers"`
Origin string `json:"origin"`
URL string `json:"url"`
}
type uuidResponse struct {
UUID string `json:"uuid"`
}
type bearerResponse struct {
Authenticated bool `json:"authenticated"`
Token string `json:"token"`
}
type hostnameResponse struct {
Hostname string `json:"hostname"`
}
type errorRespnose struct {
StatusCode int `json:"status_code"`
Error string `json:"error"`
Detail string `json:"detail,omitempty"`
}