Documentation
¶
Index ¶
- type Auther
- type Config
- type Context
- 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) QueryParam(param string) ([]byte, bool)
- func (self *HttpRequester) RequestBody() []byte
- func (self *HttpRequester) RequestId() string
- func (self *HttpRequester) ResponseContentType() 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 ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auther ¶
type Auther interface {
Auth(ctx *Context, VisitAllHeaders func(func(key, value []byte))) (int, error)
}
Auther defines request authentication.
type Config ¶
type Config struct {
LogConfig log.Configer
ErrorHandler ErrorHandler
Auther Auther
RequestValidator RequestValidator
ResponseValidator ResponseValidator
MimeTypeHandlers MimeTypeHandlers
Resources map[string]interface{}
Timeout time.Duration
}
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 Context ¶
Context defines local endpoint data.
func NewContext ¶
NewContext creates a new endpoint context. The server creates this and passes it to the endpoint handler.
func (*Context) ShouldContinue ¶
ShouldContinue returns true if the underlying request has not been cancelled nor deadline exceeded.
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 ErrorHandler interface {
// FIXME: HandlerError only really converts an error into []byte. This function definition could be made simpler.
// The error could be returned and then the internal endpoint code handles the marshaling.
HandleError(ctx *Context, httpStatus int, err error) (int, interface{})
}
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) (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) 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) 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
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
}