/
views.go
96 lines (70 loc) · 3.41 KB
/
views.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package middleware
import (
v2 "github.com/SpectoLabs/hoverfly/core/handlers/v2"
"github.com/SpectoLabs/hoverfly/core/interfaces"
"github.com/SpectoLabs/hoverfly/core/util"
)
// This is a JSON serializable representation of the internal
// Hoverfly structs for HTTP requests and responses.
// These structs are only used when serializing requests
// and responses to middleware.
type RequestResponsePairView struct {
Response ResponseDetailsView `json:"response"`
Request RequestDetailsView `json:"request"`
}
func (this RequestResponsePairView) GetResponse() interfaces.Response { return this.Response }
func (this RequestResponsePairView) GetRequest() interfaces.Request { return this.Request }
type RequestDetailsView struct {
RequestType *string `json:"requestType"`
Path *string `json:"path"`
Method *string `json:"method"`
Destination *string `json:"destination"`
Scheme *string `json:"scheme"`
Query *string `json:"query"`
Body *string `json:"body"`
FormData map[string][]string `json:"formData"`
Headers map[string][]string `json:"headers"`
}
func (this RequestDetailsView) GetPath() *string { return this.Path }
func (this RequestDetailsView) GetMethod() *string { return this.Method }
func (this RequestDetailsView) GetDestination() *string { return this.Destination }
func (this RequestDetailsView) GetScheme() *string { return this.Scheme }
func (this RequestDetailsView) GetQuery() *string {
if this.Query == nil {
return this.Query
}
queryString := util.SortQueryString(*this.Query)
return &queryString
}
func (this RequestDetailsView) GetBody() *string { return this.Body }
func (this RequestDetailsView) GetHeaders() map[string][]string { return this.Headers }
type ResponseDetailsView struct {
Status int `json:"status"`
Body string `json:"body"`
BodyFile string `json:"bodyFile"`
EncodedBody bool `json:"encodedBody"`
Headers map[string][]string `json:"headers"`
FixedDelay int `json:"fixedDelay"`
LogNormalDelay *v2.LogNormalDelayOptions `json:"logNormalDelay"`
PostServeAction string `json:"postServeAction"`
}
func (this ResponseDetailsView) GetStatus() int { return this.Status }
func (this ResponseDetailsView) GetBody() string { return this.Body }
func (this ResponseDetailsView) GetBodyFile() string { return this.BodyFile }
func (this ResponseDetailsView) GetEncodedBody() bool { return this.EncodedBody }
func (this RequestDetailsView) GetFormData() map[string][]string { return this.FormData }
func (this ResponseDetailsView) GetTemplated() bool { return false }
func (this ResponseDetailsView) GetTransitionsState() map[string]string { return nil }
func (this ResponseDetailsView) GetRemovesState() []string { return nil }
func (this ResponseDetailsView) GetHeaders() map[string][]string { return this.Headers }
func (this ResponseDetailsView) GetFixedDelay() int { return this.FixedDelay }
// The trick here to return nil with the right type to compare later.
func (this ResponseDetailsView) GetLogNormalDelay() interfaces.ResponseDelay {
if this.LogNormalDelay != nil {
return this.LogNormalDelay
}
return nil
}
func (this ResponseDetailsView) GetPostServeAction() string {
return this.PostServeAction
}