Documentation
¶
Index ¶
- Constants
- Variables
- func BoolValidator(values []string) merry.Error
- func ClientIP(r *http.Request) string
- func GenerateID(r *http.Request) string
- func HTTPListenerForAddress(addr string) (net.Listener, merry.Error)
- func PutRequest(request *Request)
- func WriteResponse(w http.ResponseWriter, response Response) (err merry.Error)
- type BasicResponse
- type CompletionHook
- type ErrorHandler
- type ErrorHook
- type FakeResponse
- func (f *FakeResponse) AssertErrCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertErrCalledN(t ResponseTestingT, n int)
- func (f *FakeResponse) AssertErrCalledOnce(t ResponseTestingT)
- func (f *FakeResponse) AssertErrNotCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertHeadersCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertHeadersCalledN(t ResponseTestingT, n int)
- func (f *FakeResponse) AssertHeadersCalledOnce(t ResponseTestingT)
- func (f *FakeResponse) AssertHeadersNotCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertSerializeCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertSerializeCalledN(t ResponseTestingT, n int)
- func (f *FakeResponse) AssertSerializeCalledOnce(t ResponseTestingT)
- func (_f17 *FakeResponse) AssertSerializeCalledOnceWith(t ResponseTestingT, ident1 io.Writer)
- func (_f15 *FakeResponse) AssertSerializeCalledWith(t ResponseTestingT, ident1 io.Writer)
- func (f *FakeResponse) AssertSerializeNotCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertStatusCodeCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertStatusCodeCalledN(t ResponseTestingT, n int)
- func (f *FakeResponse) AssertStatusCodeCalledOnce(t ResponseTestingT)
- func (f *FakeResponse) AssertStatusCodeNotCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertTrailersCalled(t ResponseTestingT)
- func (f *FakeResponse) AssertTrailersCalledN(t ResponseTestingT, n int)
- func (f *FakeResponse) AssertTrailersCalledOnce(t ResponseTestingT)
- func (f *FakeResponse) AssertTrailersNotCalled(t ResponseTestingT)
- func (_f7 *FakeResponse) Err() (ident1 error)
- func (f *FakeResponse) ErrCalled() bool
- func (f *FakeResponse) ErrCalledN(n int) bool
- func (f *FakeResponse) ErrCalledOnce() bool
- func (f *FakeResponse) ErrNotCalled() bool
- func (_f3 *FakeResponse) Headers() (ident1 http.Header)
- func (f *FakeResponse) HeadersCalled() bool
- func (f *FakeResponse) HeadersCalledN(n int) bool
- func (f *FakeResponse) HeadersCalledOnce() bool
- func (f *FakeResponse) HeadersNotCalled() bool
- func (f *FakeResponse) Reset()
- func (_f9 *FakeResponse) Serialize(ident1 io.Writer) (ident2 merry.Error)
- func (f *FakeResponse) SerializeCalled() bool
- func (f *FakeResponse) SerializeCalledN(n int) bool
- func (f *FakeResponse) SerializeCalledOnce() bool
- func (_f16 *FakeResponse) SerializeCalledOnceWith(ident1 io.Writer) bool
- func (_f14 *FakeResponse) SerializeCalledWith(ident1 io.Writer) (found bool)
- func (f *FakeResponse) SerializeNotCalled() bool
- func (_f18 *FakeResponse) SerializeResultsForCall(ident1 io.Writer) (ident2 merry.Error, found bool)
- func (_f8 *FakeResponse) SetErrStub(ident1 error)
- func (_f4 *FakeResponse) SetHeadersStub(ident1 http.Header)
- func (_f11 *FakeResponse) SetSerializeInvocation(calls_f12 []*ResponseSerializeInvocation, fallback_f13 func() merry.Error)
- func (_f10 *FakeResponse) SetSerializeStub(ident2 merry.Error)
- func (_f2 *FakeResponse) SetStatusCodeStub(ident1 int)
- func (_f6 *FakeResponse) SetTrailersStub(ident1 http.Header)
- func (_f1 *FakeResponse) StatusCode() (ident1 int)
- func (f *FakeResponse) StatusCodeCalled() bool
- func (f *FakeResponse) StatusCodeCalledN(n int) bool
- func (f *FakeResponse) StatusCodeCalledOnce() bool
- func (f *FakeResponse) StatusCodeNotCalled() bool
- func (_f5 *FakeResponse) Trailers() (ident1 http.Header)
- func (f *FakeResponse) TrailersCalled() bool
- func (f *FakeResponse) TrailersCalledN(n int) bool
- func (f *FakeResponse) TrailersCalledOnce() bool
- func (f *FakeResponse) TrailersNotCalled() bool
- type Field
- type FixedStringValidator
- type Handler
- type IntValidator
- type JsonResponse
- type PathParameter
- type QueryParameter
- func (p *QueryParameter) Bool(v *bool) merry.Error
- func (p *QueryParameter) BoolSlice(v *[]bool) merry.Error
- func (p *QueryParameter) CSV(v *[]string) merry.Error
- func (p *QueryParameter) Int(v *int) merry.Error
- func (p *QueryParameter) Int8(v *int8) merry.Error
- func (p *QueryParameter) Int8Slice(v *[]int8) merry.Error
- func (p *QueryParameter) Int16(v *int16) merry.Error
- func (p *QueryParameter) Int16Slice(v *[]int16) merry.Error
- func (p *QueryParameter) Int32(v *int32) merry.Error
- func (p *QueryParameter) Int32Slice(v *[]int32) merry.Error
- func (p *QueryParameter) Int64(v *int64) merry.Error
- func (p *QueryParameter) Int64Slice(v *[]int64) merry.Error
- func (p *QueryParameter) IntSlice(v *[]int) merry.Error
- func (p *QueryParameter) Time(v *time.Time, format string) merry.Error
- func (p *QueryParameter) TimeSlice(v *[]time.Time, format string) merry.Error
- func (p *QueryParameter) Uint(v *uint) merry.Error
- func (p *QueryParameter) Uint8(v *uint8) merry.Error
- func (p *QueryParameter) Uint8Slice(v *[]uint8) merry.Error
- func (p *QueryParameter) Uint16(v *uint16) merry.Error
- func (p *QueryParameter) Uint16Slice(v *[]uint16) merry.Error
- func (p *QueryParameter) Uint32(v *uint32) merry.Error
- func (p *QueryParameter) Uint32Slice(v *[]uint32) merry.Error
- func (p *QueryParameter) Uint64(v *uint64) merry.Error
- func (p *QueryParameter) Uint64Slice(v *[]uint64) merry.Error
- func (p *QueryParameter) UintSlice(v *[]uint) merry.Error
- type RegexValidator
- type Request
- func (r *Request) ClientIP() string
- func (r *Request) ID() string
- func (r *Request) ParseQueryParameters() bool
- func (r *Request) PathParamExists(name string) bool
- func (r *Request) QueryParamExists(name string) bool
- func (r *Request) ValidateQueryParameters(fields []Field) (malformed bool, unknown bool, exception merry.Error)
- type RequestPredicate
- type Response
- type ResponseAdapter
- type ResponseErrInvocation
- type ResponseHeadersInvocation
- type ResponseInterceptor
- func (i *ResponseInterceptor) Elapsed() time.Duration
- func (i *ResponseInterceptor) Flush() ResponseSnapshot
- func (i *ResponseInterceptor) Header() http.Header
- func (i *ResponseInterceptor) Snapshot() ResponseSnapshot
- func (i *ResponseInterceptor) Start() time.Time
- func (i *ResponseInterceptor) Write(data []byte) (int, error)
- func (i *ResponseInterceptor) WriteHeader(status int)
- func (i *ResponseInterceptor) WriteResponse(response Response) merry.Error
- type ResponseSerializeInvocation
- type ResponseSnapshot
- type ResponseStatusCodeInvocation
- type ResponseTestingT
- type ResponseTrailersInvocation
- type StringExtractor
- type StringSliceValidator
- type StringValidator
- type TimestampValidator
- type Validator
Constants ¶
const (
LocationHeaderKey = "Location"
)
Variables ¶
var ( InvalidParameterNameEscape = merry.New("invalid parameter name escape") InvalidParameterValueEscape = merry.New("invalid parameter value escape") MalformedQueryParamter = merry.New("malformed query parameter") MissingQueryParamter = merry.New("missing query parameter") UnknownQueryParamter = merry.New("unknown query parameter") )
var (
UnexpectedValue = merry.New("unexpected value")
)
Functions ¶
func BoolValidator ¶
BoolValidator enforces that all input values are parsable as a boolean
func ClientIP ¶
ClientIP attempts to extract the IP address of the user agent from the request. The "X-Real-IP" and "X-Forwarded-For" headers are checked followed by the `RemoteAddr` field of the request. An empty string will be returned if nothing can be found.
func GenerateID ¶
GenerateID creates a globally unique string for the request. It creates a version 5 UUID with the concatenation of current unix nanos, three bytes of random data, the client ip address, the request method and the request URI. This function is *not* idempotent.
func HTTPListenerForAddress ¶
HTTPListenerForAddress returns a TCP listener for the given address. If the address is empty `":http"` is used.
func PutRequest ¶
func PutRequest(request *Request)
PutRequest returns the given Request back to the shared pool.
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, response Response) (err merry.Error)
WriteResponse serializes a response instance to the ResponseWriter. `ResponseWriter.WriteHeader` will always be called with the value of `Response.StatusCode()` so it is not safe to use the `ResponseWriter` after calling this function. Any error returned from `Response.Serialize` will be returned.
Types ¶
type BasicResponse ¶
func (*BasicResponse) Err ¶
func (r *BasicResponse) Err() error
func (*BasicResponse) Headers ¶
func (r *BasicResponse) Headers() http.Header
func (*BasicResponse) StatusCode ¶
func (r *BasicResponse) StatusCode() int
func (*BasicResponse) Trailers ¶
func (r *BasicResponse) Trailers() http.Header
type CompletionHook ¶
type CompletionHook func(context.Context, *Request, ResponseSnapshot)
func (CompletionHook) InvokeSafely ¶
func (h CompletionHook) InvokeSafely(ctx context.Context, request *Request, snapshot ResponseSnapshot) (exception merry.Error)
type ErrorHandler ¶
ErrorHandler creates a response for the given error condition.
type FakeResponse ¶
type FakeResponse struct {
StatusCodeHook func() int
HeadersHook func() http.Header
TrailersHook func() http.Header
ErrHook func() error
SerializeHook func(io.Writer) merry.Error
StatusCodeCalls []*ResponseStatusCodeInvocation
HeadersCalls []*ResponseHeadersInvocation
TrailersCalls []*ResponseTrailersInvocation
ErrCalls []*ResponseErrInvocation
SerializeCalls []*ResponseSerializeInvocation
}
FakeResponse is a mock implementation of Response for testing. Use it in your tests as in this example:
package example
func TestWithResponse(t *testing.T) {
f := &httpx.FakeResponse{
StatusCodeHook: func() (ident1 int) {
// ensure parameters meet expections, signal errors using t, etc
return
},
}
// test code goes here ...
// assert state of FakeStatusCode ...
f.AssertStatusCodeCalledOnce(t)
}
Create anonymous function implementations for only those interface methods that should be called in the code under test. This will force a panic if any unexpected calls are made to FakeStatusCode.
func NewFakeResponseDefaultError ¶
func NewFakeResponseDefaultError(t ResponseTestingT) *FakeResponse
NewFakeResponseDefaultError returns an instance of FakeResponse with all hooks configured to call t.Error
func NewFakeResponseDefaultFatal ¶
func NewFakeResponseDefaultFatal(t ResponseTestingT) *FakeResponse
NewFakeResponseDefaultFatal returns an instance of FakeResponse with all hooks configured to call t.Fatal
func NewFakeResponseDefaultPanic ¶
func NewFakeResponseDefaultPanic() *FakeResponse
NewFakeResponseDefaultPanic returns an instance of FakeResponse with all hooks configured to panic
func (*FakeResponse) AssertErrCalled ¶
func (f *FakeResponse) AssertErrCalled(t ResponseTestingT)
AssertErrCalled calls t.Error if FakeResponse.Err was not called
func (*FakeResponse) AssertErrCalledN ¶
func (f *FakeResponse) AssertErrCalledN(t ResponseTestingT, n int)
AssertErrCalledN calls t.Error if FakeResponse.Err was called less than n times
func (*FakeResponse) AssertErrCalledOnce ¶
func (f *FakeResponse) AssertErrCalledOnce(t ResponseTestingT)
AssertErrCalledOnce calls t.Error if FakeResponse.Err was not called exactly once
func (*FakeResponse) AssertErrNotCalled ¶
func (f *FakeResponse) AssertErrNotCalled(t ResponseTestingT)
AssertErrNotCalled calls t.Error if FakeResponse.Err was called
func (*FakeResponse) AssertHeadersCalled ¶
func (f *FakeResponse) AssertHeadersCalled(t ResponseTestingT)
AssertHeadersCalled calls t.Error if FakeResponse.Headers was not called
func (*FakeResponse) AssertHeadersCalledN ¶
func (f *FakeResponse) AssertHeadersCalledN(t ResponseTestingT, n int)
AssertHeadersCalledN calls t.Error if FakeResponse.Headers was called less than n times
func (*FakeResponse) AssertHeadersCalledOnce ¶
func (f *FakeResponse) AssertHeadersCalledOnce(t ResponseTestingT)
AssertHeadersCalledOnce calls t.Error if FakeResponse.Headers was not called exactly once
func (*FakeResponse) AssertHeadersNotCalled ¶
func (f *FakeResponse) AssertHeadersNotCalled(t ResponseTestingT)
AssertHeadersNotCalled calls t.Error if FakeResponse.Headers was called
func (*FakeResponse) AssertSerializeCalled ¶
func (f *FakeResponse) AssertSerializeCalled(t ResponseTestingT)
AssertSerializeCalled calls t.Error if FakeResponse.Serialize was not called
func (*FakeResponse) AssertSerializeCalledN ¶
func (f *FakeResponse) AssertSerializeCalledN(t ResponseTestingT, n int)
AssertSerializeCalledN calls t.Error if FakeResponse.Serialize was called less than n times
func (*FakeResponse) AssertSerializeCalledOnce ¶
func (f *FakeResponse) AssertSerializeCalledOnce(t ResponseTestingT)
AssertSerializeCalledOnce calls t.Error if FakeResponse.Serialize was not called exactly once
func (*FakeResponse) AssertSerializeCalledOnceWith ¶
func (_f17 *FakeResponse) AssertSerializeCalledOnceWith(t ResponseTestingT, ident1 io.Writer)
AssertSerializeCalledOnceWith calls t.Error if FakeResponse.Serialize was not called exactly once with the given values
func (*FakeResponse) AssertSerializeCalledWith ¶
func (_f15 *FakeResponse) AssertSerializeCalledWith(t ResponseTestingT, ident1 io.Writer)
AssertSerializeCalledWith calls t.Error if FakeResponse.Serialize was not called with the given values
func (*FakeResponse) AssertSerializeNotCalled ¶
func (f *FakeResponse) AssertSerializeNotCalled(t ResponseTestingT)
AssertSerializeNotCalled calls t.Error if FakeResponse.Serialize was called
func (*FakeResponse) AssertStatusCodeCalled ¶
func (f *FakeResponse) AssertStatusCodeCalled(t ResponseTestingT)
AssertStatusCodeCalled calls t.Error if FakeResponse.StatusCode was not called
func (*FakeResponse) AssertStatusCodeCalledN ¶
func (f *FakeResponse) AssertStatusCodeCalledN(t ResponseTestingT, n int)
AssertStatusCodeCalledN calls t.Error if FakeResponse.StatusCode was called less than n times
func (*FakeResponse) AssertStatusCodeCalledOnce ¶
func (f *FakeResponse) AssertStatusCodeCalledOnce(t ResponseTestingT)
AssertStatusCodeCalledOnce calls t.Error if FakeResponse.StatusCode was not called exactly once
func (*FakeResponse) AssertStatusCodeNotCalled ¶
func (f *FakeResponse) AssertStatusCodeNotCalled(t ResponseTestingT)
AssertStatusCodeNotCalled calls t.Error if FakeResponse.StatusCode was called
func (*FakeResponse) AssertTrailersCalled ¶
func (f *FakeResponse) AssertTrailersCalled(t ResponseTestingT)
AssertTrailersCalled calls t.Error if FakeResponse.Trailers was not called
func (*FakeResponse) AssertTrailersCalledN ¶
func (f *FakeResponse) AssertTrailersCalledN(t ResponseTestingT, n int)
AssertTrailersCalledN calls t.Error if FakeResponse.Trailers was called less than n times
func (*FakeResponse) AssertTrailersCalledOnce ¶
func (f *FakeResponse) AssertTrailersCalledOnce(t ResponseTestingT)
AssertTrailersCalledOnce calls t.Error if FakeResponse.Trailers was not called exactly once
func (*FakeResponse) AssertTrailersNotCalled ¶
func (f *FakeResponse) AssertTrailersNotCalled(t ResponseTestingT)
AssertTrailersNotCalled calls t.Error if FakeResponse.Trailers was called
func (*FakeResponse) Err ¶
func (_f7 *FakeResponse) Err() (ident1 error)
func (*FakeResponse) ErrCalled ¶
func (f *FakeResponse) ErrCalled() bool
ErrCalled returns true if FakeResponse.Err was called
func (*FakeResponse) ErrCalledN ¶
func (f *FakeResponse) ErrCalledN(n int) bool
ErrCalledN returns true if FakeResponse.Err was called at least n times
func (*FakeResponse) ErrCalledOnce ¶
func (f *FakeResponse) ErrCalledOnce() bool
ErrCalledOnce returns true if FakeResponse.Err was called exactly once
func (*FakeResponse) ErrNotCalled ¶
func (f *FakeResponse) ErrNotCalled() bool
ErrNotCalled returns true if FakeResponse.Err was not called
func (*FakeResponse) Headers ¶
func (_f3 *FakeResponse) Headers() (ident1 http.Header)
func (*FakeResponse) HeadersCalled ¶
func (f *FakeResponse) HeadersCalled() bool
HeadersCalled returns true if FakeResponse.Headers was called
func (*FakeResponse) HeadersCalledN ¶
func (f *FakeResponse) HeadersCalledN(n int) bool
HeadersCalledN returns true if FakeResponse.Headers was called at least n times
func (*FakeResponse) HeadersCalledOnce ¶
func (f *FakeResponse) HeadersCalledOnce() bool
HeadersCalledOnce returns true if FakeResponse.Headers was called exactly once
func (*FakeResponse) HeadersNotCalled ¶
func (f *FakeResponse) HeadersNotCalled() bool
HeadersNotCalled returns true if FakeResponse.Headers was not called
func (*FakeResponse) Reset ¶
func (f *FakeResponse) Reset()
func (*FakeResponse) Serialize ¶
func (_f9 *FakeResponse) Serialize(ident1 io.Writer) (ident2 merry.Error)
func (*FakeResponse) SerializeCalled ¶
func (f *FakeResponse) SerializeCalled() bool
SerializeCalled returns true if FakeResponse.Serialize was called
func (*FakeResponse) SerializeCalledN ¶
func (f *FakeResponse) SerializeCalledN(n int) bool
SerializeCalledN returns true if FakeResponse.Serialize was called at least n times
func (*FakeResponse) SerializeCalledOnce ¶
func (f *FakeResponse) SerializeCalledOnce() bool
SerializeCalledOnce returns true if FakeResponse.Serialize was called exactly once
func (*FakeResponse) SerializeCalledOnceWith ¶
func (_f16 *FakeResponse) SerializeCalledOnceWith(ident1 io.Writer) bool
SerializeCalledOnceWith returns true if FakeResponse.Serialize was called exactly once with the given values
func (*FakeResponse) SerializeCalledWith ¶
func (_f14 *FakeResponse) SerializeCalledWith(ident1 io.Writer) (found bool)
SerializeCalledWith returns true if FakeResponse.Serialize was called with the given values
func (*FakeResponse) SerializeNotCalled ¶
func (f *FakeResponse) SerializeNotCalled() bool
SerializeNotCalled returns true if FakeResponse.Serialize was not called
func (*FakeResponse) SerializeResultsForCall ¶
func (_f18 *FakeResponse) SerializeResultsForCall(ident1 io.Writer) (ident2 merry.Error, found bool)
SerializeResultsForCall returns the result values for the first call to FakeResponse.Serialize with the given values
func (*FakeResponse) SetErrStub ¶ added in v0.3.1
func (_f8 *FakeResponse) SetErrStub(ident1 error)
SetErrStub configures Response.Err to always return the given values
func (*FakeResponse) SetHeadersStub ¶ added in v0.3.1
func (_f4 *FakeResponse) SetHeadersStub(ident1 http.Header)
SetHeadersStub configures Response.Headers to always return the given values
func (*FakeResponse) SetSerializeInvocation ¶ added in v0.3.1
func (_f11 *FakeResponse) SetSerializeInvocation(calls_f12 []*ResponseSerializeInvocation, fallback_f13 func() merry.Error)
SetSerializeInvocation configures Response.Serialize to return the given results when called with the given parameters If no match is found for an invocation the result(s) of the fallback function are returned
func (*FakeResponse) SetSerializeStub ¶ added in v0.3.1
func (_f10 *FakeResponse) SetSerializeStub(ident2 merry.Error)
SetSerializeStub configures Response.Serialize to always return the given values
func (*FakeResponse) SetStatusCodeStub ¶ added in v0.3.1
func (_f2 *FakeResponse) SetStatusCodeStub(ident1 int)
SetStatusCodeStub configures Response.StatusCode to always return the given values
func (*FakeResponse) SetTrailersStub ¶ added in v0.3.1
func (_f6 *FakeResponse) SetTrailersStub(ident1 http.Header)
SetTrailersStub configures Response.Trailers to always return the given values
func (*FakeResponse) StatusCode ¶
func (_f1 *FakeResponse) StatusCode() (ident1 int)
func (*FakeResponse) StatusCodeCalled ¶
func (f *FakeResponse) StatusCodeCalled() bool
StatusCodeCalled returns true if FakeResponse.StatusCode was called
func (*FakeResponse) StatusCodeCalledN ¶
func (f *FakeResponse) StatusCodeCalledN(n int) bool
StatusCodeCalledN returns true if FakeResponse.StatusCode was called at least n times
func (*FakeResponse) StatusCodeCalledOnce ¶
func (f *FakeResponse) StatusCodeCalledOnce() bool
StatusCodeCalledOnce returns true if FakeResponse.StatusCode was called exactly once
func (*FakeResponse) StatusCodeNotCalled ¶
func (f *FakeResponse) StatusCodeNotCalled() bool
StatusCodeNotCalled returns true if FakeResponse.StatusCode was not called
func (*FakeResponse) Trailers ¶
func (_f5 *FakeResponse) Trailers() (ident1 http.Header)
func (*FakeResponse) TrailersCalled ¶
func (f *FakeResponse) TrailersCalled() bool
TrailersCalled returns true if FakeResponse.Trailers was called
func (*FakeResponse) TrailersCalledN ¶
func (f *FakeResponse) TrailersCalledN(n int) bool
TrailersCalledN returns true if FakeResponse.Trailers was called at least n times
func (*FakeResponse) TrailersCalledOnce ¶
func (f *FakeResponse) TrailersCalledOnce() bool
TrailersCalledOnce returns true if FakeResponse.Trailers was called exactly once
func (*FakeResponse) TrailersNotCalled ¶
func (f *FakeResponse) TrailersNotCalled() bool
TrailersNotCalled returns true if FakeResponse.Trailers was not called
type Field ¶
type Field struct {
Name string // Match keys by exact value
Regex *regexp.Regexp // Match keys by pattern
Default string `json:",omitempty"` // Default value for `Name`
Validator Validator `json:"-"` // Optional validator of value(s)
Multiplicity uint `json:",omitempty"` // Value count, 0 is unlimited
Required bool // Is this input mandatory?
}
Field is the schema to validate a query parameter or request body. Either `Name` or `Regex` _should_ be provided. Providing `Default` *requires* `Name`. If `Default` is provided and a matching input is not presented then a syntheitic value will be created.
type FixedStringValidator ¶
type FixedStringValidator struct {
Target string
}
FixedStringValidator enforces that all input values match a fixed string
type Handler ¶
Handler is a block of logic to apply to a request. Returning a non-nil Response indicates request processing should stop.
type IntValidator ¶
IntValidator enforces that all input values are parsable as integers. It also optionally enforces that values are within a range.
type JsonResponse ¶
type JsonResponse struct {
BasicResponse
Payload json.Marshaler
}
type PathParameter ¶
PathParameter is a single URL path parameter.
type QueryParameter ¶
type QueryParameter struct {
Name string // the key of the query parameter pair
Values []string // the concatenated values
Err merry.Error // the param is unparsable or invalid
}
QueryParameter is a single URL query parameter passed to an endpoint.
func (*QueryParameter) Int16Slice ¶
func (p *QueryParameter) Int16Slice(v *[]int16) merry.Error
func (*QueryParameter) Int32Slice ¶
func (p *QueryParameter) Int32Slice(v *[]int32) merry.Error
func (*QueryParameter) Int64Slice ¶
func (p *QueryParameter) Int64Slice(v *[]int64) merry.Error
func (*QueryParameter) Uint8Slice ¶
func (p *QueryParameter) Uint8Slice(v *[]uint8) merry.Error
func (*QueryParameter) Uint16Slice ¶
func (p *QueryParameter) Uint16Slice(v *[]uint16) merry.Error
func (*QueryParameter) Uint32Slice ¶
func (p *QueryParameter) Uint32Slice(v *[]uint32) merry.Error
func (*QueryParameter) Uint64Slice ¶
func (p *QueryParameter) Uint64Slice(v *[]uint64) merry.Error
type RegexValidator ¶
RegexValidator enforces that all input values match the given regular expression.
type Request ¶
type Request struct {
*http.Request
PathParams []PathParameter
QueryParams []*QueryParameter
// contains filtered or unexported fields
}
func GetRequest ¶
GetRequest returns a Request instance from the shared pool, ready for (re)use.
func (*Request) ClientIP ¶
ClientIP attempts to extract the IP address of the user agent from the request. The "X-Real-IP" and "X-Forwarded-For" headers are checked followed by the `RemoteAddr` field of the request. An empty string will be returned if nothing can be found.
func (*Request) ID ¶
ID returns a globally unique string for the request. It creates a version 5 UUID with the concatenation of current unix nanos, three bytes of random data, the client ip address, the request method and the request URI. This method is idempotent.
func (*Request) ParseQueryParameters ¶
ParseQueryParameters parses the URL-encoded query string and fills in the `QueryParams` field. Any existing values will be lost when this method is called.
func (*Request) PathParamExists ¶
func (*Request) QueryParamExists ¶
func (*Request) ValidateQueryParameters ¶
func (r *Request) ValidateQueryParameters(fields []Field) (malformed bool, unknown bool, exception merry.Error)
ValidateQueryParameters validates the values in `QueryParams` with the provided fields. If no fields are given, no action will be taken. Validation errors are assigned to the problematic parameter and placeholder instances are created for missing required or unknown parameters.
The `malformed` and `unknown` return values indicate if any paramters fail validation or do not match a field, respectively. If a validator panics an error will be returned in `err`.
type RequestPredicate ¶
RequestPredicate examines the given context and request and returns a determination based on that analysis.
func (RequestPredicate) InvokeSafely ¶
type Response ¶
type Response interface {
StatusCode() int
Headers() http.Header
Trailers() http.Header
Err() error
Serialize(io.Writer) merry.Error
}
func NewEmptyError ¶
func NewSeeOther ¶
func NewTemporaryRedirect ¶
type ResponseAdapter ¶
ResponseAdapter is an adapter for `http.Response` to the `Response` interface.
func (ResponseAdapter) Err ¶
func (r ResponseAdapter) Err() error
func (ResponseAdapter) Headers ¶
func (r ResponseAdapter) Headers() http.Header
func (ResponseAdapter) StatusCode ¶
func (r ResponseAdapter) StatusCode() int
func (ResponseAdapter) Trailers ¶
func (r ResponseAdapter) Trailers() http.Header
type ResponseErrInvocation ¶
type ResponseErrInvocation struct {
Results struct {
Ident1 error
}
}
ResponseErrInvocation represents a single call of FakeResponse.Err
type ResponseHeadersInvocation ¶
ResponseHeadersInvocation represents a single call of FakeResponse.Headers
type ResponseInterceptor ¶
type ResponseInterceptor struct {
http.ResponseWriter
// contains filtered or unexported fields
}
ResponseInterceptor implements `http.ResponseWriter` to capture the outgoing response status code and size.
func NewInterceptor ¶
func NewInterceptor(w http.ResponseWriter) *ResponseInterceptor
func (*ResponseInterceptor) Elapsed ¶
func (i *ResponseInterceptor) Elapsed() time.Duration
Elapsed returns the amount of time since this instance was created.
func (*ResponseInterceptor) Flush ¶
func (i *ResponseInterceptor) Flush() ResponseSnapshot
Flush attempts to call the `Flush` method on the underlying `ResponseWriter`, if it implments the `http.Flusher` interface.
func (*ResponseInterceptor) Header ¶
func (i *ResponseInterceptor) Header() http.Header
func (*ResponseInterceptor) Snapshot ¶
func (i *ResponseInterceptor) Snapshot() ResponseSnapshot
func (*ResponseInterceptor) Start ¶ added in v0.3.1
func (i *ResponseInterceptor) Start() time.Time
Start returns the time this instance was created.
func (*ResponseInterceptor) WriteHeader ¶
func (i *ResponseInterceptor) WriteHeader(status int)
func (*ResponseInterceptor) WriteResponse ¶
func (i *ResponseInterceptor) WriteResponse(response Response) merry.Error
WriteResponse serializes a response instance The `WriteHeader` method will *always* be called with the value of `Response.StatusCode()` so it is not safe to use the `ResponseWriter` methods of this instance after calling this method. Any error returned from `Response.Serialize` will be returned.
type ResponseSerializeInvocation ¶
type ResponseSerializeInvocation struct {
Parameters struct {
Ident1 io.Writer
}
Results struct {
Ident2 merry.Error
}
}
ResponseSerializeInvocation represents a single call of FakeResponse.Serialize
func NewResponseSerializeInvocation ¶ added in v0.3.1
func NewResponseSerializeInvocation(ident1 io.Writer, ident2 merry.Error) *ResponseSerializeInvocation
NewResponseSerializeInvocation creates a new instance of ResponseSerializeInvocation
type ResponseSnapshot ¶
type ResponseSnapshot struct {
// Status code returned to the user agent
StatusCode int
// Size of the response body in bytes
Size int
// Time request servicing began
Start time.Time
// Duration of request servicing
Elapsed time.Duration
}
ResponseSnapshot captures details about the response sent to the user agent.
type ResponseStatusCodeInvocation ¶
type ResponseStatusCodeInvocation struct {
Results struct {
Ident1 int
}
}
ResponseStatusCodeInvocation represents a single call of FakeResponse.StatusCode
type ResponseTestingT ¶
type ResponseTestingT interface {
Error(...interface{})
Errorf(string, ...interface{})
Fatal(...interface{})
Helper()
}
ResponseTestingT represents the methods of "testing".T used by charlatan Fakes. It avoids importing the testing package.
type ResponseTrailersInvocation ¶
ResponseTrailersInvocation represents a single call of FakeResponse.Trailers
type StringExtractor ¶
StringExtractor is a function type that extracts a string from the given `context.Context` and `*httpx.Request`. An error is returned if the string could not be extracted.
type StringSliceValidator ¶
type StringSliceValidator struct {
Target []string
}
StringSliceValidator enforces that all input values match at least one of the given strings
type StringValidator ¶
StringValidator enforces that all input values have a certain length
type TimestampValidator ¶
TimestampValidator enforces that all input values are parsable as a timestamp with a certain format. It also optionally enforces the time value falls within a range.