Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// Request is the request being served.
Request *Request
// Provided holds the data of the server's template data providers, by key: {{ .Provided.user }}.
Provided map[string]any
// KV reads the server's key-value store: {{ .KV.Get "key" }} and {{ .KV.Has "key" }}.
KV *KVView
// Server describes the mock server.
Server *Server
// Data is the data of the server, set with its SetData: {{ .Data.target }}.
Data map[string]any
// Extra is the template data of the reply being rendered: a mock file's template.data. Other templates, such as
// a webhook's, don't have it.
Extra any
// Scenarios reads the state of the server's scenarios: {{ .Scenarios.State "checkout" }}, and of the instance of
// a key, {{ .Scenarios.StateOf "checkout" (.Request.Header.Get "X-Test-Id") }}. A scenario the mock that matched
// moved is in the state it moved it to, even once another request moved it on.
Scenarios matchscenario.View
}
Data is what templates render with: the dot of a Go template, and the context of any other engine.
type Request ¶
type Request struct {
// ID identifies the request, as the ID of its mockhttp.RequestValues.
ID string
Method string
// URL is the request URL: the one a request in absolute form, as a forward proxy gets, or an intercepted one names,
// and otherwise on the server's base URL.
URL *url.URL
// URLPathSegments are the segments of the URL path, each decoded: /users/1 is [users 1], and /files/a%2Fb is
// [files a/b].
URLPathSegments []string
// PathParams holds the parameters of the path template of the mock that matched, decoded, by name: /users/{id}
// gives {{ .Request.PathParams.id }}. A mock without one has none.
PathParams map[string]string
Header http.Header
// Cookies holds the cookies of the request, by name.
Cookies map[string]*http.Cookie
// Body is the body of the request, or nil when it has none: see HasBody.
Body *Body
// PostForm holds the text fields of a form body, urlencoded or multipart: {{ .Request.PostForm.Get "name" }}.
PostForm url.Values
// MultipartForm is the multipart form of the body, as http.Request.ParseMultipartForm left it, or nil.
MultipartForm *multipart.Form
}
Request is the request being served.
type Server ¶
type Server struct {
// URL is the base URL of the server, such as http://127.0.0.1:8080: {{ .Server.URL }}/callback.
URL string
}
Server describes the mock server to templates.
Click to show internal directories.
Click to hide internal directories.