Documentation ¶
Index ¶
- Constants
- Variables
- func BuildMockScenarioKeyData(req *http.Request) (keyData *types.APIKeyData, err error)
- func GetHeaderParamOrEnvValue(params map[string]string, names ...string) string
- func NewStubContext(req *http.Request) *stubContext
- type APIContext
- type AWSSigner
- type Adapter
- type AuthAdapter
- type DefaultAPIContext
- func (d *DefaultAPIContext) Attachment(_ string, _ string) error
- func (d *DefaultAPIContext) Blob(code int, contentType string, b []byte) error
- func (d *DefaultAPIContext) Cookie(name string) (*http.Cookie, error)
- func (d *DefaultAPIContext) FormParams() (url.Values, error)
- func (d *DefaultAPIContext) FormValue(name string) string
- func (d *DefaultAPIContext) Get(key string) any
- func (d *DefaultAPIContext) Host() string
- func (d *DefaultAPIContext) JSON(code int, i any) error
- func (d *DefaultAPIContext) MultipartForm() (*multipart.Form, error)
- func (d *DefaultAPIContext) NoContent(code int) error
- func (d *DefaultAPIContext) Param(name string) string
- func (d *DefaultAPIContext) Path() string
- func (d *DefaultAPIContext) QueryParam(name string) string
- func (d *DefaultAPIContext) QueryParams() url.Values
- func (d *DefaultAPIContext) Redirect(code int, url string) error
- func (d *DefaultAPIContext) Render(_ int, _ string, _ any) error
- func (d *DefaultAPIContext) Request() *http.Request
- func (d *DefaultAPIContext) Response() *echo.Response
- func (d *DefaultAPIContext) Set(key string, val any)
- func (d *DefaultAPIContext) SetCookie(cookie *http.Cookie)
- func (d *DefaultAPIContext) Stream(code int, contentType string, r io.Reader) (err error)
- func (d *DefaultAPIContext) String(code int, s string) error
- type DefaultHTTPClient
- type DefaultWebServer
- func (w *DefaultWebServer) AddMiddleware(m echo.MiddlewareFunc)
- func (w *DefaultWebServer) CONNECT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) DELETE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) Embed(content embed.FS, path string, dir string)
- func (w *DefaultWebServer) GET(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) HEAD(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) OPTIONS(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) PATCH(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) POST(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) PUT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- func (w *DefaultWebServer) Start(address string)
- func (w *DefaultWebServer) Static(path string, dir string)
- func (w *DefaultWebServer) Stop()
- func (w *DefaultWebServer) TRACE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
- type HTTPClient
- type HandlerFunc
- type MethodPathHandler
- type Server
- type ServerAdapter
- func (a *ServerAdapter) AddMiddleware(_ echo.MiddlewareFunc)
- func (a *ServerAdapter) CONNECT(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) DELETE(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) Embed(embed.FS, string, string)
- func (a *ServerAdapter) GET(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) HEAD(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) Invoke(request *http.Request) (response *http.Response, err error)
- func (a *ServerAdapter) OPTIONS(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) PATCH(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) POST(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) PUT(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- func (a *ServerAdapter) Start(string)
- func (a *ServerAdapter) Static(string, string)
- func (a *ServerAdapter) Stop()
- func (a *ServerAdapter) TRACE(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
- type StubHTTPClient
- type StubHTTPResponse
- type StubResponseWriter
Constants ¶
const AWSAccessKey = "AWS_ACCESS_KEY_ID"
AWSAccessKey constant
const AWSSecretKey = "AWS_SECRET_ACCESS_KEY"
AWSSecretKey constant
const AWSSecurityToken = "AWS_SECURITY_TOKEN"
AWSSecurityToken constant
const AWSSessionToken = "AWS_SESSION_TOKEN"
AWSSessionToken constant
Variables ¶
var IgnoredRequestHeaders = map[string]struct{}{ types.AuthorizationHeader: {}, types.ContentLengthHeader: {}, "User-Agent": {}, "Accept": {}, "Accept-Language": {}, "Accept-Encoding": {}, "Connection": {}, "Proxy-Connection": {}, "Origin": {}, "Referer": {}, "Host": {}, "X-Amzn-Trace-Id": {}, "X-Requested-With": {}, "X-Amz-Requestsupertrace": {}, "X-Amz-Security-Token": {}, "Sec-Fetch-Dest": {}, "Sec-Fetch-Mode": {}, "Sec-Fetch-Site": {}, "Sec-GPC": {}, }
IgnoredRequestHeaders headers
Functions ¶
func BuildMockScenarioKeyData ¶
func BuildMockScenarioKeyData(req *http.Request) (keyData *types.APIKeyData, err error)
BuildMockScenarioKeyData creates api-scenario key from HTTP request
func GetHeaderParamOrEnvValue ¶
GetHeaderParamOrEnvValue searches key in map or env variables
func NewStubContext ¶
NewStubContext - creates stubbed server
Types ¶
type APIContext ¶
type APIContext interface { // Path Request path Path() string // Request returns `*http.Request`. Request() *http.Request // Response returns `*Response`. Response() *echo.Response // Param returns path parameter by name. Param(name string) string // QueryParams returns the query parameters as `url.Values`. QueryParams() url.Values // QueryParam returns the query param for the provided name. QueryParam(name string) string // FormParams returns the form parameters as `url.Values`. FormParams() (url.Values, error) // FormValue returns the form field value for the provided name. FormValue(name string) string // Cookie returns the named cookie provided in the request. Cookie(name string) (*http.Cookie, error) // SetCookie adds a `Set-Cookie` header in HTTP response. SetCookie(cookie *http.Cookie) // Get retrieves data from the context. Get(key string) any // Set saves data in the context. Set(key string, val any) // Render renders a template with data and sends a text/html response with status // code. Renderer must be registered using `Echo.Renderer`. Render(code int, name string, data any) error // String sends a string response with status code. String(code int, s string) error // JSON sends a JSON response with status code. JSON(code int, i any) error // MultipartForm returns the multipart form. MultipartForm() (*multipart.Form, error) // Redirect redirects the request to a provided URL with status code. Redirect(code int, url string) error // NoContent sends a response with nobody and a status code. NoContent(code int) error // Blob sends a blob response with status code and content type. Blob(code int, contentType string, b []byte) error // Stream sends a streaming response with status code and content type. Stream(code int, contentType string, r io.Reader) error // Attachment sends a response as attachment, prompting client to save the // file. Attachment(file string, name string) error }
APIContext interface
type AWSSigner ¶
type AWSSigner interface {
AWSSign(req *http.Request, credentials *credentials.Credentials) (bool, string, error)
}
AWSSigner is an interface to make testing http.Client calls easier
func NewAWSSigner ¶
func NewAWSSigner(config *types.Configuration) AWSSigner
NewAWSSigner constructor
type Adapter ¶
type Adapter interface { // Invoke http method Invoke(request *http.Request) (response *http.Response, err error) }
Adapter defines methods to delegate HTTP APIs
type AuthAdapter ¶
AuthAdapter is an interface to make testing http.Client calls easier
func NewAuthAdapter ¶
func NewAuthAdapter(config *types.Configuration) AuthAdapter
NewAuthAdapter constructor
type DefaultAPIContext ¶
type DefaultAPIContext struct {
// contains filtered or unexported fields
}
DefaultAPIContext struct for defining APIContext using http request/response
func (*DefaultAPIContext) Attachment ¶
func (d *DefaultAPIContext) Attachment(_ string, _ string) error
Attachment sends a response as attachment, prompting client to save the file.
func (*DefaultAPIContext) Blob ¶
func (d *DefaultAPIContext) Blob(code int, contentType string, b []byte) error
Blob sends a blob response with status code and content type.
func (*DefaultAPIContext) Cookie ¶
func (d *DefaultAPIContext) Cookie(name string) (*http.Cookie, error)
Cookie returns the named cookie provided in the request.
func (*DefaultAPIContext) FormParams ¶
func (d *DefaultAPIContext) FormParams() (url.Values, error)
FormParams returns the form parameters as `url.Values`.
func (*DefaultAPIContext) FormValue ¶
func (d *DefaultAPIContext) FormValue(name string) string
FormValue returns the form field value for the provided name.
func (*DefaultAPIContext) Get ¶
func (d *DefaultAPIContext) Get(key string) any
Get retrieves data from the context.
func (*DefaultAPIContext) JSON ¶
func (d *DefaultAPIContext) JSON(code int, i any) error
JSON sends a JSON response with status code.
func (*DefaultAPIContext) MultipartForm ¶
func (d *DefaultAPIContext) MultipartForm() (*multipart.Form, error)
MultipartForm returns the multipart form.
func (*DefaultAPIContext) NoContent ¶
func (d *DefaultAPIContext) NoContent(code int) error
NoContent sends a response with nobody and a status code.
func (*DefaultAPIContext) Param ¶
func (d *DefaultAPIContext) Param(name string) string
Param returns path parameter by name.
func (*DefaultAPIContext) QueryParam ¶
func (d *DefaultAPIContext) QueryParam(name string) string
QueryParam returns the query param for the provided name.
func (*DefaultAPIContext) QueryParams ¶
func (d *DefaultAPIContext) QueryParams() url.Values
QueryParams returns the query parameters as `url.Values`.
func (*DefaultAPIContext) Redirect ¶
func (d *DefaultAPIContext) Redirect(code int, url string) error
Redirect redirects the request to a provided URL with status code.
func (*DefaultAPIContext) Render ¶
func (d *DefaultAPIContext) Render(_ int, _ string, _ any) error
Render renders a template with data and sends a text/html response with status code. Renderer must be registered using `Echo.Renderer`.
func (*DefaultAPIContext) Request ¶
func (d *DefaultAPIContext) Request() *http.Request
Request returns `*http.Request`.
func (*DefaultAPIContext) Response ¶
func (d *DefaultAPIContext) Response() *echo.Response
Response returns `*Response`.
func (*DefaultAPIContext) Set ¶
func (d *DefaultAPIContext) Set(key string, val any)
Set saves data in the context.
func (*DefaultAPIContext) SetCookie ¶
func (d *DefaultAPIContext) SetCookie(cookie *http.Cookie)
SetCookie adds a `Set-Cookie` header in HTTP response.
type DefaultHTTPClient ¶
type DefaultHTTPClient struct {
// contains filtered or unexported fields
}
DefaultHTTPClient implements HTTPClient
func NewHTTPClient ¶
func NewHTTPClient(config *types.Configuration, authAdapter AuthAdapter) *DefaultHTTPClient
NewHTTPClient creates structure for HTTPClient
func (*DefaultHTTPClient) Handle ¶
func (w *DefaultHTTPClient) Handle( ctx context.Context, url string, method string, headers map[string][]string, params map[string]string, body io.ReadCloser, ) (statusCode int, httpVersion string, respBody io.ReadCloser, respHeader map[string][]string, err error)
Handle makes HTTP request
type DefaultWebServer ¶
type DefaultWebServer struct {
// contains filtered or unexported fields
}
DefaultWebServer defines default web server
func (*DefaultWebServer) AddMiddleware ¶
func (w *DefaultWebServer) AddMiddleware(m echo.MiddlewareFunc)
AddMiddleware adds middleware
func (*DefaultWebServer) CONNECT ¶
func (w *DefaultWebServer) CONNECT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
CONNECT calls HTTP CONNECT method
func (*DefaultWebServer) DELETE ¶
func (w *DefaultWebServer) DELETE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
DELETE calls HTTP DELETE method
func (*DefaultWebServer) Embed ¶
func (w *DefaultWebServer) Embed(content embed.FS, path string, dir string)
Embed - serve assets
func (*DefaultWebServer) GET ¶
func (w *DefaultWebServer) GET(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
GET calls HTTP GET method
func (*DefaultWebServer) HEAD ¶
func (w *DefaultWebServer) HEAD(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
HEAD calls HTTP HEAD method
func (*DefaultWebServer) OPTIONS ¶
func (w *DefaultWebServer) OPTIONS(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
OPTIONS calls HTTP OPTIONS method
func (*DefaultWebServer) PATCH ¶
func (w *DefaultWebServer) PATCH(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PATCH calls HTTP PATCH method
func (*DefaultWebServer) POST ¶
func (w *DefaultWebServer) POST(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
POST calls HTTP POST method
func (*DefaultWebServer) PUT ¶
func (w *DefaultWebServer) PUT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PUT calls HTTP PUT method
func (*DefaultWebServer) Start ¶
func (w *DefaultWebServer) Start(address string)
Start - starts web server
func (*DefaultWebServer) Static ¶
func (w *DefaultWebServer) Static(path string, dir string)
Static - serve assets
func (*DefaultWebServer) TRACE ¶
func (w *DefaultWebServer) TRACE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
TRACE calls HTTP TRACE method
type HTTPClient ¶
type HTTPClient interface { Handle( ctx context.Context, url string, method string, headers map[string][]string, params map[string]string, body io.ReadCloser, ) (int, string, io.ReadCloser, map[string][]string, error) }
HTTPClient defines methods for http get and post methods
type HandlerFunc ¶
type HandlerFunc func(APIContext) error
HandlerFunc defines a function to serve HTTP requests.
func WrapHandler ¶
func WrapHandler(h http.Handler) HandlerFunc
WrapHandler wraps `http.Handler` into `echo.HandlerFunc`.
type MethodPathHandler ¶
type MethodPathHandler struct {
// contains filtered or unexported fields
}
MethodPathHandler mapping
type Server ¶
type Server interface { GET(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route POST(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route PUT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route DELETE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route CONNECT(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route HEAD(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route OPTIONS(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route PATCH(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route TRACE(path string, h HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route AddMiddleware(m echo.MiddlewareFunc) Start(address string) Static(path string, dir string) Embed(content embed.FS, path string, dir string) Stop() }
Server defines methods for binding http methods
func NewDefaultWebServer ¶
func NewDefaultWebServer(config *types.Configuration) Server
NewDefaultWebServer creates new instance of web server
type ServerAdapter ¶
type ServerAdapter struct {
// contains filtered or unexported fields
}
ServerAdapter struct
func NewWebServerAdapter ¶
func NewWebServerAdapter() *ServerAdapter
NewWebServerAdapter constructor
func (*ServerAdapter) AddMiddleware ¶
func (a *ServerAdapter) AddMiddleware(_ echo.MiddlewareFunc)
AddMiddleware middleware
func (*ServerAdapter) CONNECT ¶
func (a *ServerAdapter) CONNECT(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
CONNECT calls HTTP CONNECT method
func (*ServerAdapter) DELETE ¶
func (a *ServerAdapter) DELETE(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
DELETE handler calls HTTP DELETE method
func (*ServerAdapter) Embed ¶
func (a *ServerAdapter) Embed(embed.FS, string, string)
Embed skeleton
func (*ServerAdapter) GET ¶
func (a *ServerAdapter) GET(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
GET handler calls HTTP GET method
func (*ServerAdapter) HEAD ¶
func (a *ServerAdapter) HEAD(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
HEAD calls HTTP HEAD method
func (*ServerAdapter) OPTIONS ¶
func (a *ServerAdapter) OPTIONS(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
OPTIONS calls HTTP OPTIONS method
func (*ServerAdapter) PATCH ¶
func (a *ServerAdapter) PATCH(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
PATCH calls HTTP PATCH method
func (*ServerAdapter) POST ¶
func (a *ServerAdapter) POST(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
POST handler calls HTTP POST method
func (*ServerAdapter) PUT ¶
func (a *ServerAdapter) PUT(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
PUT handler calls HTTP PUT method
func (*ServerAdapter) Static ¶
func (a *ServerAdapter) Static(string, string)
Static serve static assets
func (*ServerAdapter) TRACE ¶
func (a *ServerAdapter) TRACE(path string, handler HandlerFunc, _ ...echo.MiddlewareFunc) *echo.Route
TRACE calls HTTP TRACE method
type StubHTTPClient ¶
type StubHTTPClient struct {
// contains filtered or unexported fields
}
StubHTTPClient implements HTTPClient for stubbed response
func NewStubHTTPClient ¶
func NewStubHTTPClient() *StubHTTPClient
NewStubHTTPClient - creates structure for HTTPClient
func (*StubHTTPClient) AddMapping ¶
func (w *StubHTTPClient) AddMapping(method string, url string, resp *StubHTTPResponse)
AddMapping adds mapping for stub response
type StubHTTPResponse ¶
type StubHTTPResponse struct { Filename string Bytes []byte Status int Headers map[string][]string Error error // contains filtered or unexported fields }
StubHTTPResponse defines stub response
func NewStubHTTPResponse ¶
func NewStubHTTPResponse(status int, unk any) *StubHTTPResponse
NewStubHTTPResponse creates stubbed response
func NewStubHTTPResponseError ¶
func NewStubHTTPResponseError(status int, sleep time.Duration, err error) *StubHTTPResponse
NewStubHTTPResponseError creates stubbed response with error
func (*StubHTTPResponse) WithHeader ¶
func (r *StubHTTPResponse) WithHeader(name string, val string) *StubHTTPResponse
type StubResponseWriter ¶
type StubResponseWriter struct {
// contains filtered or unexported fields
}
StubResponseWriter wraps the standard http.ResponseWriter allowing for more verbose logging
func (*StubResponseWriter) Header ¶
func (w *StubResponseWriter) Header() http.Header
Header returns & satisfies the http.ResponseWriter interface
func (*StubResponseWriter) Size ¶
func (w *StubResponseWriter) Size() int
Size provides an easy way to retrieve the response size in bytes
func (*StubResponseWriter) Status ¶
func (w *StubResponseWriter) Status() int
Status provides an easy way to retrieve the status code
func (*StubResponseWriter) Write ¶
func (w *StubResponseWriter) Write(_ []byte) (int, error)
Write satisfies the http.ResponseWriter interface and captures data written, in bytes
func (*StubResponseWriter) WriteHeader ¶
func (w *StubResponseWriter) WriteHeader(statusCode int)
WriteHeader satisfies the http.ResponseWriter interface and allows us to catch the status code