Documentation
¶
Index ¶
- Variables
- type Authorizer
- type AuthorizerAuthorizeInvocation
- type AuthorizerTestingT
- type DebugServer
- type FakeAuthorizer
- func (f *FakeAuthorizer) AssertAuthorizeCalled(t AuthorizerTestingT)
- func (f *FakeAuthorizer) AssertAuthorizeCalledN(t AuthorizerTestingT, n int)
- func (f *FakeAuthorizer) AssertAuthorizeCalledOnce(t AuthorizerTestingT)
- func (_f5 *FakeAuthorizer) AssertAuthorizeCalledOnceWith(t AuthorizerTestingT, ident1 context.Context, ident2 *httpx.Request)
- func (_f3 *FakeAuthorizer) AssertAuthorizeCalledWith(t AuthorizerTestingT, ident1 context.Context, ident2 *httpx.Request)
- func (f *FakeAuthorizer) AssertAuthorizeNotCalled(t AuthorizerTestingT)
- func (_f1 *FakeAuthorizer) Authorize(ident1 context.Context, ident2 *httpx.Request) (ident3 bool, ident4 merry.Error)
- func (f *FakeAuthorizer) AuthorizeCalled() bool
- func (f *FakeAuthorizer) AuthorizeCalledN(n int) bool
- func (f *FakeAuthorizer) AuthorizeCalledOnce() bool
- func (_f4 *FakeAuthorizer) AuthorizeCalledOnceWith(ident1 context.Context, ident2 *httpx.Request) bool
- func (_f2 *FakeAuthorizer) AuthorizeCalledWith(ident1 context.Context, ident2 *httpx.Request) (found bool)
- func (f *FakeAuthorizer) AuthorizeNotCalled() bool
- func (_f6 *FakeAuthorizer) AuthorizeResultsForCall(ident1 context.Context, ident2 *httpx.Request) (ident3 bool, ident4 merry.Error, found bool)
- func (f *FakeAuthorizer) Reset()
- type FakeServer
- func (_f2 *FakeServer) Address() (ident1 string)
- func (f *FakeServer) AddressCalled() bool
- func (f *FakeServer) AddressCalledN(n int) bool
- func (f *FakeServer) AddressCalledOnce() bool
- func (f *FakeServer) AddressNotCalled() bool
- func (f *FakeServer) AssertAddressCalled(t ServerTestingT)
- func (f *FakeServer) AssertAddressCalledN(t ServerTestingT, n int)
- func (f *FakeServer) AssertAddressCalledOnce(t ServerTestingT)
- func (f *FakeServer) AssertAddressNotCalled(t ServerTestingT)
- func (f *FakeServer) AssertListenCalled(t ServerTestingT)
- func (f *FakeServer) AssertListenCalledN(t ServerTestingT, n int)
- func (f *FakeServer) AssertListenCalledOnce(t ServerTestingT)
- func (f *FakeServer) AssertListenNotCalled(t ServerTestingT)
- func (f *FakeServer) AssertNameCalled(t ServerTestingT)
- func (f *FakeServer) AssertNameCalledN(t ServerTestingT, n int)
- func (f *FakeServer) AssertNameCalledOnce(t ServerTestingT)
- func (f *FakeServer) AssertNameNotCalled(t ServerTestingT)
- func (f *FakeServer) AssertServeCalled(t ServerTestingT)
- func (f *FakeServer) AssertServeCalledN(t ServerTestingT, n int)
- func (f *FakeServer) AssertServeCalledOnce(t ServerTestingT)
- func (f *FakeServer) AssertServeNotCalled(t ServerTestingT)
- func (f *FakeServer) AssertShutdownCalled(t ServerTestingT)
- func (f *FakeServer) AssertShutdownCalledN(t ServerTestingT, n int)
- func (f *FakeServer) AssertShutdownCalledOnce(t ServerTestingT)
- func (_f9 *FakeServer) AssertShutdownCalledOnceWith(t ServerTestingT, ident1 time.Duration)
- func (_f7 *FakeServer) AssertShutdownCalledWith(t ServerTestingT, ident1 time.Duration)
- func (f *FakeServer) AssertShutdownNotCalled(t ServerTestingT)
- func (_f3 *FakeServer) Listen() (ident1 error)
- func (f *FakeServer) ListenCalled() bool
- func (f *FakeServer) ListenCalledN(n int) bool
- func (f *FakeServer) ListenCalledOnce() bool
- func (f *FakeServer) ListenNotCalled() bool
- func (_f1 *FakeServer) Name() (ident1 string)
- func (f *FakeServer) NameCalled() bool
- func (f *FakeServer) NameCalledN(n int) bool
- func (f *FakeServer) NameCalledOnce() bool
- func (f *FakeServer) NameNotCalled() bool
- func (f *FakeServer) Reset()
- func (_f4 *FakeServer) Serve() (ident1 error)
- func (f *FakeServer) ServeCalled() bool
- func (f *FakeServer) ServeCalledN(n int) bool
- func (f *FakeServer) ServeCalledOnce() bool
- func (f *FakeServer) ServeNotCalled() bool
- func (_f5 *FakeServer) Shutdown(ident1 time.Duration) (ident2 error)
- func (f *FakeServer) ShutdownCalled() bool
- func (f *FakeServer) ShutdownCalledN(n int) bool
- func (f *FakeServer) ShutdownCalledOnce() bool
- func (_f8 *FakeServer) ShutdownCalledOnceWith(ident1 time.Duration) bool
- func (_f6 *FakeServer) ShutdownCalledWith(ident1 time.Duration) (found bool)
- func (f *FakeServer) ShutdownNotCalled() bool
- func (_f10 *FakeServer) ShutdownResultsForCall(ident1 time.Duration) (ident2 error, found bool)
- type HTTPServer
- func (s *HTTPServer) Address() string
- func (s *HTTPServer) Authenticate(ctx context.Context, request *httpx.Request) (response httpx.Response)
- func (s *HTTPServer) Authorize(ctx context.Context, request *httpx.Request) (response httpx.Response)
- func (s *HTTPServer) Listen() (err error)
- func (s *HTTPServer) Serve() error
- func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *HTTPServer) Shutdown(timeout time.Duration) error
- type HealthcheckServer
- type Healthchecker
- type Router
- type Server
- type ServerAddressInvocation
- type ServerListenInvocation
- type ServerNameInvocation
- type ServerServeInvocation
- type ServerShutdownInvocation
- type ServerTestingT
Constants ¶
This section is empty.
Variables ¶
var (
AuxiliaryStats = new(expvar.Map)
)
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer interface {
// Authorize returns `true` if the principal in the context
// object is allowed to peform the given request. If the
// principal is not allowed `false` must be returned, not an
// error. If there is a problem completing authorization an
// error should be returned.
Authorize(context.Context, *httpx.Request) (bool, merry.Error)
}
Authorizer defines a provider for authorizing principals to make requests.
type AuthorizerAuthorizeInvocation ¶
type AuthorizerAuthorizeInvocation struct {
Parameters struct {
Ident1 context.Context
Ident2 *httpx.Request
}
Results struct {
Ident3 bool
Ident4 merry.Error
}
}
AuthorizerAuthorizeInvocation represents a single call of FakeAuthorizer.Authorize
type AuthorizerTestingT ¶
type AuthorizerTestingT interface {
Error(...interface{})
Errorf(string, ...interface{})
Fatal(...interface{})
Helper()
}
AuthorizerTestingT represents the methods of "testing".T used by charlatan Fakes. It avoids importing the testing package.
type DebugServer ¶
type DebugServer struct {
HTTPServer
Path string // URL path to listen on, "/debug/vars" if empty
}
DebugServer serves values from the `expvar` package to the configured address and path.
func (*DebugServer) Name ¶
func (s *DebugServer) Name() string
func (*DebugServer) Serve ¶
func (s *DebugServer) Serve() error
type FakeAuthorizer ¶
type FakeAuthorizer struct {
AuthorizeHook func(context.Context, *httpx.Request) (bool, merry.Error)
AuthorizeCalls []*AuthorizerAuthorizeInvocation
}
FakeAuthorizer is a mock implementation of Authorizer for testing. Use it in your tests as in this example:
package example
func TestWithAuthorizer(t *testing.T) {
f := &auxiliary.FakeAuthorizer{
AuthorizeHook: func(ident1 context.Context, ident2 *httpx.Request) (ident3 bool, ident4 merry.Error) {
// ensure parameters meet expections, signal errors using t, etc
return
},
}
// test code goes here ...
// assert state of FakeAuthorize ...
f.AssertAuthorizeCalledOnce(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 FakeAuthorize.
func NewFakeAuthorizerDefaultError ¶
func NewFakeAuthorizerDefaultError(t AuthorizerTestingT) *FakeAuthorizer
NewFakeAuthorizerDefaultError returns an instance of FakeAuthorizer with all hooks configured to call t.Error
func NewFakeAuthorizerDefaultFatal ¶
func NewFakeAuthorizerDefaultFatal(t AuthorizerTestingT) *FakeAuthorizer
NewFakeAuthorizerDefaultFatal returns an instance of FakeAuthorizer with all hooks configured to call t.Fatal
func NewFakeAuthorizerDefaultPanic ¶
func NewFakeAuthorizerDefaultPanic() *FakeAuthorizer
NewFakeAuthorizerDefaultPanic returns an instance of FakeAuthorizer with all hooks configured to panic
func (*FakeAuthorizer) AssertAuthorizeCalled ¶
func (f *FakeAuthorizer) AssertAuthorizeCalled(t AuthorizerTestingT)
AssertAuthorizeCalled calls t.Error if FakeAuthorizer.Authorize was not called
func (*FakeAuthorizer) AssertAuthorizeCalledN ¶
func (f *FakeAuthorizer) AssertAuthorizeCalledN(t AuthorizerTestingT, n int)
AssertAuthorizeCalledN calls t.Error if FakeAuthorizer.Authorize was called less than n times
func (*FakeAuthorizer) AssertAuthorizeCalledOnce ¶
func (f *FakeAuthorizer) AssertAuthorizeCalledOnce(t AuthorizerTestingT)
AssertAuthorizeCalledOnce calls t.Error if FakeAuthorizer.Authorize was not called exactly once
func (*FakeAuthorizer) AssertAuthorizeCalledOnceWith ¶
func (_f5 *FakeAuthorizer) AssertAuthorizeCalledOnceWith(t AuthorizerTestingT, ident1 context.Context, ident2 *httpx.Request)
AssertAuthorizeCalledOnceWith calls t.Error if FakeAuthorizer.Authorize was not called exactly once with the given values
func (*FakeAuthorizer) AssertAuthorizeCalledWith ¶
func (_f3 *FakeAuthorizer) AssertAuthorizeCalledWith(t AuthorizerTestingT, ident1 context.Context, ident2 *httpx.Request)
AssertAuthorizeCalledWith calls t.Error if FakeAuthorizer.Authorize was not called with the given values
func (*FakeAuthorizer) AssertAuthorizeNotCalled ¶
func (f *FakeAuthorizer) AssertAuthorizeNotCalled(t AuthorizerTestingT)
AssertAuthorizeNotCalled calls t.Error if FakeAuthorizer.Authorize was called
func (*FakeAuthorizer) AuthorizeCalled ¶
func (f *FakeAuthorizer) AuthorizeCalled() bool
AuthorizeCalled returns true if FakeAuthorizer.Authorize was called
func (*FakeAuthorizer) AuthorizeCalledN ¶
func (f *FakeAuthorizer) AuthorizeCalledN(n int) bool
AuthorizeCalledN returns true if FakeAuthorizer.Authorize was called at least n times
func (*FakeAuthorizer) AuthorizeCalledOnce ¶
func (f *FakeAuthorizer) AuthorizeCalledOnce() bool
AuthorizeCalledOnce returns true if FakeAuthorizer.Authorize was called exactly once
func (*FakeAuthorizer) AuthorizeCalledOnceWith ¶
func (_f4 *FakeAuthorizer) AuthorizeCalledOnceWith(ident1 context.Context, ident2 *httpx.Request) bool
AuthorizeCalledOnceWith returns true if FakeAuthorizer.Authorize was called exactly once with the given values
func (*FakeAuthorizer) AuthorizeCalledWith ¶
func (_f2 *FakeAuthorizer) AuthorizeCalledWith(ident1 context.Context, ident2 *httpx.Request) (found bool)
AuthorizeCalledWith returns true if FakeAuthorizer.Authorize was called with the given values
func (*FakeAuthorizer) AuthorizeNotCalled ¶
func (f *FakeAuthorizer) AuthorizeNotCalled() bool
AuthorizeNotCalled returns true if FakeAuthorizer.Authorize was not called
func (*FakeAuthorizer) AuthorizeResultsForCall ¶
func (_f6 *FakeAuthorizer) AuthorizeResultsForCall(ident1 context.Context, ident2 *httpx.Request) (ident3 bool, ident4 merry.Error, found bool)
AuthorizeResultsForCall returns the result values for the first call to FakeAuthorizer.Authorize with the given values
func (*FakeAuthorizer) Reset ¶
func (f *FakeAuthorizer) Reset()
type FakeServer ¶
type FakeServer struct {
NameHook func() string
AddressHook func() string
ListenHook func() error
ServeHook func() error
ShutdownHook func(time.Duration) error
NameCalls []*ServerNameInvocation
AddressCalls []*ServerAddressInvocation
ListenCalls []*ServerListenInvocation
ServeCalls []*ServerServeInvocation
ShutdownCalls []*ServerShutdownInvocation
}
FakeServer is a mock implementation of Server for testing. Use it in your tests as in this example:
package example
func TestWithServer(t *testing.T) {
f := &auxiliary.FakeServer{
NameHook: func() (ident1 string) {
// ensure parameters meet expections, signal errors using t, etc
return
},
}
// test code goes here ...
// assert state of FakeName ...
f.AssertNameCalledOnce(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 FakeName.
func NewFakeServerDefaultError ¶
func NewFakeServerDefaultError(t ServerTestingT) *FakeServer
NewFakeServerDefaultError returns an instance of FakeServer with all hooks configured to call t.Error
func NewFakeServerDefaultFatal ¶
func NewFakeServerDefaultFatal(t ServerTestingT) *FakeServer
NewFakeServerDefaultFatal returns an instance of FakeServer with all hooks configured to call t.Fatal
func NewFakeServerDefaultPanic ¶
func NewFakeServerDefaultPanic() *FakeServer
NewFakeServerDefaultPanic returns an instance of FakeServer with all hooks configured to panic
func (*FakeServer) Address ¶
func (_f2 *FakeServer) Address() (ident1 string)
func (*FakeServer) AddressCalled ¶
func (f *FakeServer) AddressCalled() bool
AddressCalled returns true if FakeServer.Address was called
func (*FakeServer) AddressCalledN ¶
func (f *FakeServer) AddressCalledN(n int) bool
AddressCalledN returns true if FakeServer.Address was called at least n times
func (*FakeServer) AddressCalledOnce ¶
func (f *FakeServer) AddressCalledOnce() bool
AddressCalledOnce returns true if FakeServer.Address was called exactly once
func (*FakeServer) AddressNotCalled ¶
func (f *FakeServer) AddressNotCalled() bool
AddressNotCalled returns true if FakeServer.Address was not called
func (*FakeServer) AssertAddressCalled ¶
func (f *FakeServer) AssertAddressCalled(t ServerTestingT)
AssertAddressCalled calls t.Error if FakeServer.Address was not called
func (*FakeServer) AssertAddressCalledN ¶
func (f *FakeServer) AssertAddressCalledN(t ServerTestingT, n int)
AssertAddressCalledN calls t.Error if FakeServer.Address was called less than n times
func (*FakeServer) AssertAddressCalledOnce ¶
func (f *FakeServer) AssertAddressCalledOnce(t ServerTestingT)
AssertAddressCalledOnce calls t.Error if FakeServer.Address was not called exactly once
func (*FakeServer) AssertAddressNotCalled ¶
func (f *FakeServer) AssertAddressNotCalled(t ServerTestingT)
AssertAddressNotCalled calls t.Error if FakeServer.Address was called
func (*FakeServer) AssertListenCalled ¶
func (f *FakeServer) AssertListenCalled(t ServerTestingT)
AssertListenCalled calls t.Error if FakeServer.Listen was not called
func (*FakeServer) AssertListenCalledN ¶
func (f *FakeServer) AssertListenCalledN(t ServerTestingT, n int)
AssertListenCalledN calls t.Error if FakeServer.Listen was called less than n times
func (*FakeServer) AssertListenCalledOnce ¶
func (f *FakeServer) AssertListenCalledOnce(t ServerTestingT)
AssertListenCalledOnce calls t.Error if FakeServer.Listen was not called exactly once
func (*FakeServer) AssertListenNotCalled ¶
func (f *FakeServer) AssertListenNotCalled(t ServerTestingT)
AssertListenNotCalled calls t.Error if FakeServer.Listen was called
func (*FakeServer) AssertNameCalled ¶
func (f *FakeServer) AssertNameCalled(t ServerTestingT)
AssertNameCalled calls t.Error if FakeServer.Name was not called
func (*FakeServer) AssertNameCalledN ¶
func (f *FakeServer) AssertNameCalledN(t ServerTestingT, n int)
AssertNameCalledN calls t.Error if FakeServer.Name was called less than n times
func (*FakeServer) AssertNameCalledOnce ¶
func (f *FakeServer) AssertNameCalledOnce(t ServerTestingT)
AssertNameCalledOnce calls t.Error if FakeServer.Name was not called exactly once
func (*FakeServer) AssertNameNotCalled ¶
func (f *FakeServer) AssertNameNotCalled(t ServerTestingT)
AssertNameNotCalled calls t.Error if FakeServer.Name was called
func (*FakeServer) AssertServeCalled ¶
func (f *FakeServer) AssertServeCalled(t ServerTestingT)
AssertServeCalled calls t.Error if FakeServer.Serve was not called
func (*FakeServer) AssertServeCalledN ¶
func (f *FakeServer) AssertServeCalledN(t ServerTestingT, n int)
AssertServeCalledN calls t.Error if FakeServer.Serve was called less than n times
func (*FakeServer) AssertServeCalledOnce ¶
func (f *FakeServer) AssertServeCalledOnce(t ServerTestingT)
AssertServeCalledOnce calls t.Error if FakeServer.Serve was not called exactly once
func (*FakeServer) AssertServeNotCalled ¶
func (f *FakeServer) AssertServeNotCalled(t ServerTestingT)
AssertServeNotCalled calls t.Error if FakeServer.Serve was called
func (*FakeServer) AssertShutdownCalled ¶
func (f *FakeServer) AssertShutdownCalled(t ServerTestingT)
AssertShutdownCalled calls t.Error if FakeServer.Shutdown was not called
func (*FakeServer) AssertShutdownCalledN ¶
func (f *FakeServer) AssertShutdownCalledN(t ServerTestingT, n int)
AssertShutdownCalledN calls t.Error if FakeServer.Shutdown was called less than n times
func (*FakeServer) AssertShutdownCalledOnce ¶
func (f *FakeServer) AssertShutdownCalledOnce(t ServerTestingT)
AssertShutdownCalledOnce calls t.Error if FakeServer.Shutdown was not called exactly once
func (*FakeServer) AssertShutdownCalledOnceWith ¶
func (_f9 *FakeServer) AssertShutdownCalledOnceWith(t ServerTestingT, ident1 time.Duration)
AssertShutdownCalledOnceWith calls t.Error if FakeServer.Shutdown was not called exactly once with the given values
func (*FakeServer) AssertShutdownCalledWith ¶
func (_f7 *FakeServer) AssertShutdownCalledWith(t ServerTestingT, ident1 time.Duration)
AssertShutdownCalledWith calls t.Error if FakeServer.Shutdown was not called with the given values
func (*FakeServer) AssertShutdownNotCalled ¶
func (f *FakeServer) AssertShutdownNotCalled(t ServerTestingT)
AssertShutdownNotCalled calls t.Error if FakeServer.Shutdown was called
func (*FakeServer) Listen ¶
func (_f3 *FakeServer) Listen() (ident1 error)
func (*FakeServer) ListenCalled ¶
func (f *FakeServer) ListenCalled() bool
ListenCalled returns true if FakeServer.Listen was called
func (*FakeServer) ListenCalledN ¶
func (f *FakeServer) ListenCalledN(n int) bool
ListenCalledN returns true if FakeServer.Listen was called at least n times
func (*FakeServer) ListenCalledOnce ¶
func (f *FakeServer) ListenCalledOnce() bool
ListenCalledOnce returns true if FakeServer.Listen was called exactly once
func (*FakeServer) ListenNotCalled ¶
func (f *FakeServer) ListenNotCalled() bool
ListenNotCalled returns true if FakeServer.Listen was not called
func (*FakeServer) Name ¶
func (_f1 *FakeServer) Name() (ident1 string)
func (*FakeServer) NameCalled ¶
func (f *FakeServer) NameCalled() bool
NameCalled returns true if FakeServer.Name was called
func (*FakeServer) NameCalledN ¶
func (f *FakeServer) NameCalledN(n int) bool
NameCalledN returns true if FakeServer.Name was called at least n times
func (*FakeServer) NameCalledOnce ¶
func (f *FakeServer) NameCalledOnce() bool
NameCalledOnce returns true if FakeServer.Name was called exactly once
func (*FakeServer) NameNotCalled ¶
func (f *FakeServer) NameNotCalled() bool
NameNotCalled returns true if FakeServer.Name was not called
func (*FakeServer) Reset ¶
func (f *FakeServer) Reset()
func (*FakeServer) Serve ¶
func (_f4 *FakeServer) Serve() (ident1 error)
func (*FakeServer) ServeCalled ¶
func (f *FakeServer) ServeCalled() bool
ServeCalled returns true if FakeServer.Serve was called
func (*FakeServer) ServeCalledN ¶
func (f *FakeServer) ServeCalledN(n int) bool
ServeCalledN returns true if FakeServer.Serve was called at least n times
func (*FakeServer) ServeCalledOnce ¶
func (f *FakeServer) ServeCalledOnce() bool
ServeCalledOnce returns true if FakeServer.Serve was called exactly once
func (*FakeServer) ServeNotCalled ¶
func (f *FakeServer) ServeNotCalled() bool
ServeNotCalled returns true if FakeServer.Serve was not called
func (*FakeServer) ShutdownCalled ¶
func (f *FakeServer) ShutdownCalled() bool
ShutdownCalled returns true if FakeServer.Shutdown was called
func (*FakeServer) ShutdownCalledN ¶
func (f *FakeServer) ShutdownCalledN(n int) bool
ShutdownCalledN returns true if FakeServer.Shutdown was called at least n times
func (*FakeServer) ShutdownCalledOnce ¶
func (f *FakeServer) ShutdownCalledOnce() bool
ShutdownCalledOnce returns true if FakeServer.Shutdown was called exactly once
func (*FakeServer) ShutdownCalledOnceWith ¶
func (_f8 *FakeServer) ShutdownCalledOnceWith(ident1 time.Duration) bool
ShutdownCalledOnceWith returns true if FakeServer.Shutdown was called exactly once with the given values
func (*FakeServer) ShutdownCalledWith ¶
func (_f6 *FakeServer) ShutdownCalledWith(ident1 time.Duration) (found bool)
ShutdownCalledWith returns true if FakeServer.Shutdown was called with the given values
func (*FakeServer) ShutdownNotCalled ¶
func (f *FakeServer) ShutdownNotCalled() bool
ShutdownNotCalled returns true if FakeServer.Shutdown was not called
func (*FakeServer) ShutdownResultsForCall ¶
func (_f10 *FakeServer) ShutdownResultsForCall(ident1 time.Duration) (ident2 error, found bool)
ShutdownResultsForCall returns the result values for the first call to FakeServer.Shutdown with the given values
type HTTPServer ¶
type HTTPServer struct {
Addr string // TCP address to listen on, ":http" if empty
UseTLS bool // should this server use TLS?
DisableKeepAlive bool // Should TCP keep alive be disabled?
// TLSConfig is optional TLS configuration,
// This must be non-nil and properly initialized if `UseTLS`
// is `true`.
TLSConfig *tls.Config
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
//
// Because ReadTimeout does not let Handlers make per-request
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration
// ReadHeaderTimeout is the amount of time allowed to read
// request headers. The connection's read deadline is reset
// after reading the headers and the Handler can decide what
// is considered too slow for the body.
ReadHeaderTimeout time.Duration
// WriteTimeout is the maximum duration before timing out
// writes of the response. It is reset whenever a new
// request's header is read. Like ReadTimeout, it does not
// let Handlers make decisions on a per-request basis.
WriteTimeout time.Duration
// IdleTimeout is the maximum amount of time to wait for the
// next request when keep-alives are enabled. If IdleTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, ReadHeaderTimeout is used.
IdleTimeout time.Duration
// MaxHeaderBytes controls the maximum number of bytes the
// server will read parsing the request header's keys and
// values, including the request line. It does not limit the
// size of the request body.
// If zero, DefaultMaxHeaderBytes is used.
MaxHeaderBytes int
// TLSNextProto optionally specifies a function to take over
// ownership of the provided TLS connection when an NPN/ALPN
// protocol upgrade has occurred. The map key is the protocol
// name negotiated. The Handler argument should be used to
// handle HTTP requests and will initialize the Request's TLS
// and RemoteAddr if not already set. The connection is
// automatically closed when the function returns.
// If TLSNextProto is not nil, HTTP/2 support is not enabled
// automatically.
TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler)
// RequestIDHeaderName optionally customizes the name of the
// response header for the request id.
// If empty "X-Request-Id" will be used.
RequestIDHeaderName string
// RequestIDGenerator optionally customizes how request ids
// are generated.
// If nil then `httpx.Request.GenerateID` will be used.
RequestIDGenerator httpx.StringExtractor
// Authentication optionally enforces authentication before
// other request handling. This is recommended to prevent
// leaking details about the implementation to unknown user
// agents.
Authentication *middleware.Authentication
// Authorizer optionally enforces authentication before other
// request handling. Use of this field requires the
// `Authentication` field to be configured and return a
// principal.
Authorizer Authorizer
// Router is called by the `ServeHTTP` method to find the
// correct handler to invoke for the current request.
// If nil is returned a 404 status code with an empty body is
// returned to the user agent.
Router Router
// ErrorHook optionally customizes how errors encountered
// servicing a request are disposed.
// If nil no action will be taken.
ErrorHook httpx.ErrorHook
// CompletionHook optionally customizes the behavior after
// a request has been serviced.
// If nil no action will be taken.
CompletionHook httpx.CompletionHook
// contains filtered or unexported fields
}
func (*HTTPServer) Address ¶
func (s *HTTPServer) Address() string
func (*HTTPServer) Authenticate ¶
func (*HTTPServer) Listen ¶
func (s *HTTPServer) Listen() (err error)
func (*HTTPServer) Serve ¶
func (s *HTTPServer) Serve() error
func (*HTTPServer) ServeHTTP ¶
func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HealthcheckServer ¶
type HealthcheckServer struct {
HTTPServer
Path string // URL path to listen on, "/healthcheck" if empty
// Checkers are the resources to include in the status report.
Checkers []Healthchecker
}
HealthcheckServer serves JSON status reports of all configured `Healthchecker` resources to the given address and path. If all resources return no error a 200 status code is returned, otherwise a 503 is returned. The status report is a JSON Resource with the `Name()` of the resources as keys and either the `merry.UserMessage` of the error or `"OK"` as the value.
func (*HealthcheckServer) Listen ¶
func (s *HealthcheckServer) Listen() error
func (*HealthcheckServer) Name ¶
func (s *HealthcheckServer) Name() string
type Healthchecker ¶
type Healthchecker interface {
// Name is the resource's name for external reporting
Name() string
// Healthcheck should return an error if the resource has a
// problem and should not be considered reliable for further
// requests.
Healthcheck(context.Context) merry.Error
}
Healthchecker is a named resource that can report its status. If the resource is unable to perform its function it should return an error with the UserMessage explaining the problem.
type ServerAddressInvocation ¶
type ServerAddressInvocation struct {
Results struct {
Ident1 string
}
}
ServerAddressInvocation represents a single call of FakeServer.Address
type ServerListenInvocation ¶
type ServerListenInvocation struct {
Results struct {
Ident1 error
}
}
ServerListenInvocation represents a single call of FakeServer.Listen
type ServerNameInvocation ¶
type ServerNameInvocation struct {
Results struct {
Ident1 string
}
}
ServerNameInvocation represents a single call of FakeServer.Name
type ServerServeInvocation ¶
type ServerServeInvocation struct {
Results struct {
Ident1 error
}
}
ServerServeInvocation represents a single call of FakeServer.Serve
type ServerShutdownInvocation ¶
type ServerShutdownInvocation struct {
Parameters struct {
Ident1 time.Duration
}
Results struct {
Ident2 error
}
}
ServerShutdownInvocation represents a single call of FakeServer.Shutdown
type ServerTestingT ¶
type ServerTestingT interface {
Error(...interface{})
Errorf(string, ...interface{})
Fatal(...interface{})
Helper()
}
ServerTestingT represents the methods of "testing".T used by charlatan Fakes. It avoids importing the testing package.