Documentation ¶
Index ¶
- Variables
- func ShouldContinue(ctx context.Context) bool
- type Authorizer
- type Config
- type Endpoint
- type ErrorHandler
- type Handler
- type HttpRequester
- func (self *HttpRequester) Accept() []byte
- func (self *HttpRequester) ContentType() []byte
- func (self *HttpRequester) MatchedPath() string
- func (self *HttpRequester) Method() []byte
- func (self *HttpRequester) Path() []byte
- func (self *HttpRequester) PathParam(param string) (string, bool)
- func (self *HttpRequester) PeekHeader(key string) []byte
- func (self *HttpRequester) QueryParam(param string) ([]byte, bool)
- func (self *HttpRequester) RequestBody() []byte
- func (self *HttpRequester) RequestId() string
- func (self *HttpRequester) ResponseContentType() string
- func (self *HttpRequester) ResponseHeaders() map[string]string
- func (self *HttpRequester) SetResponseContentType(contentType string)
- func (self *HttpRequester) SetResponseHeader(header string, value string)
- func (self *HttpRequester) VisitHeaders(f func(key []byte, value []byte))
- type Marshaler
- type MimeTypeHandler
- type MimeTypeHandlers
- type RequestValidator
- type Requester
- type ResponseValidator
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
var ( ErrInternalServerError = errors.New(icInternalServerError, "internal server error") ErrBadRequest = errors.New(icBadRequest, "bad request") )
Functions ¶
func ShouldContinue ¶ added in v0.0.5
ShouldContinue returns true if the underlying request has not been cancelled nor deadline exceeded.
Types ¶
type Authorizer ¶ added in v0.0.9
type Authorizer interface {
Authorization(ctx context.Context, PeekHeader func(key string) []byte) (int, error)
}
Authorizer defines request authentication.
type Config ¶
type Config struct { LogConfig log.Configer ErrorHandler ErrorHandler RequestValidator RequestValidator ResponseValidator ResponseValidator MimeTypeHandlers MimeTypeHandlers Resources map[string]interface{} Timeout time.Duration Tracer opentracing.Tracer }
Config defines the behavior of an endpoint. Endpoint behavior is interface driven and can be completely modified by an application. The values in the config must never be modified by an endpoint.
type Endpoint ¶
type Endpoint struct { Config *Config // contains filtered or unexported fields }
Endpoint defines the behavior of a given handler.
func NewEndpoint ¶
Create a new endpoint that will run the given handler. This will be created by the Server during normal operations.
type ErrorHandler ¶
type Handler ¶
type Handler interface { // Handle business logic. // While not explicitly prevented, this function should // not touch the request or do any post processing of // any request data. Handle(ctx context.Context) (int, error) }
Handler is the hook into the request handler. Handler struct should contain all data that should be
populated and validated before any business logic is run.
type HttpRequester ¶ added in v0.0.4
type HttpRequester struct {
// contains filtered or unexported fields
}
func NewHttpRequester ¶ added in v0.0.4
func NewHttpRequester(matchedPath string, request *http.Request) *HttpRequester
func (*HttpRequester) Accept ¶ added in v0.0.4
func (self *HttpRequester) Accept() []byte
func (*HttpRequester) ContentType ¶ added in v0.0.4
func (self *HttpRequester) ContentType() []byte
func (*HttpRequester) MatchedPath ¶ added in v0.0.4
func (self *HttpRequester) MatchedPath() string
func (*HttpRequester) Method ¶ added in v0.0.4
func (self *HttpRequester) Method() []byte
func (*HttpRequester) Path ¶ added in v0.0.4
func (self *HttpRequester) Path() []byte
func (*HttpRequester) PathParam ¶ added in v0.0.4
func (self *HttpRequester) PathParam(param string) (string, bool)
func (*HttpRequester) PeekHeader ¶ added in v0.0.6
func (self *HttpRequester) PeekHeader(key string) []byte
func (*HttpRequester) QueryParam ¶ added in v0.0.4
func (self *HttpRequester) QueryParam(param string) ([]byte, bool)
func (*HttpRequester) RequestBody ¶ added in v0.0.4
func (self *HttpRequester) RequestBody() []byte
func (*HttpRequester) RequestId ¶ added in v0.0.4
func (self *HttpRequester) RequestId() string
func (*HttpRequester) ResponseContentType ¶ added in v0.0.4
func (self *HttpRequester) ResponseContentType() string
func (*HttpRequester) ResponseHeaders ¶ added in v0.0.6
func (self *HttpRequester) ResponseHeaders() map[string]string
func (*HttpRequester) SetResponseContentType ¶ added in v0.0.4
func (self *HttpRequester) SetResponseContentType(contentType string)
func (*HttpRequester) SetResponseHeader ¶ added in v0.0.4
func (self *HttpRequester) SetResponseHeader(header string, value string)
func (*HttpRequester) VisitHeaders ¶ added in v0.0.4
func (self *HttpRequester) VisitHeaders(f func(key []byte, value []byte))
type MimeTypeHandler ¶
type MimeTypeHandler struct { MimeType string Marshal Marshaler Unmarshal Unmarshaler }
MimeTypeHandler defines how a mime type is used. This is used by the "mime" struct tag option.
type MimeTypeHandlers ¶ added in v0.0.3
type MimeTypeHandlers map[string]*MimeTypeHandler
func NewMimeTypeHandlers ¶ added in v0.0.3
func NewMimeTypeHandlers() MimeTypeHandlers
func (MimeTypeHandlers) Get ¶ added in v0.0.3
func (m MimeTypeHandlers) Get(contentType []byte, supportedMimeTypes []string) (*MimeTypeHandler, bool)
Get the MIME type handler for the request content type as well as checking that it is supported by the endpoint.
type RequestValidator ¶
type Requester ¶ added in v0.0.4
type Requester interface { RequestId() string // HTTP Method. Method() []byte // Path of the actual request URL. Path() []byte ContentType() []byte Accept() []byte PeekHeader(key string) []byte VisitHeaders(f func(key []byte, value []byte)) // MatchedPath returns the endpoint path that the request URL matches. // Ex: /some/path/{id} MatchedPath() string // PathParam returns the path parameter value for the given parameter name. // Returns false if parameter not found. PathParam(param string) (string, bool) QueryParam(param string) ([]byte, bool) RequestBody() []byte SetResponseHeader(header string, value string) SetResponseContentType(contentType string) ResponseContentType() string ResponseHeaders() map[string]string }
type ResponseValidator ¶
type ResponseValidator interface { // ValidateRequest and return validation failures. // Errors returned are passed straight through to the ErrorHandler. // Returned status code is not used unless error is not nil. ValidateResponse(ctx context.Context, httpStatus int, responseBody []byte) (int, error) }