Documentation ¶
Index ¶
- Variables
- func EncodeResponse(s interface{}, err error, w http.ResponseWriter) error
- func Forward(c *Controller) http.HandlerFunc
- func IsRetryable(err error) (bool, time.Duration)
- func NewErrorResponse(e *ControllerError, v interface{}) (s interface{})
- func Reject(c *Controller) http.HandlerFunc
- type Controller
- func (c *Controller) Attach(router *mux.Router, handlerFunc HandlerFunc)
- func (c *Controller) Close()
- func (c *Controller) Init(opts *Options) error
- func (c *Controller) Run() error
- func (c *Controller) Send(w http.ResponseWriter, r *http.Request)
- func (ctrl *Controller) WithLogger(log Logger) *Controller
- type ControllerError
- func NewControllerError(sc int) *ControllerError
- func NewErrBadRequest() *ControllerError
- func NewErrInternalServerError() *ControllerError
- func NewErrNotAcceptable() *ControllerError
- func NewErrNotFound() *ControllerError
- func NewErrNotImplemented() *ControllerError
- func NewErrorNotReady() *ControllerError
- func (e *ControllerError) Cause() string
- func (e *ControllerError) Error() string
- func (e *ControllerError) IsRetryable() bool
- func (e *ControllerError) ResourceType() string
- func (e *ControllerError) RetryDelay() time.Duration
- func (e *ControllerError) StatusCode() int
- func (e *ControllerError) Unwrap() error
- func (e *ControllerError) WithCause(cause string) *ControllerError
- func (e *ControllerError) WithError(err error) *ControllerError
- func (e *ControllerError) WithEvent(event interface{}) *ControllerError
- func (e *ControllerError) WithResourceType(t string) *ControllerError
- func (e *ControllerError) WithRetryDelay(delay time.Duration) *ControllerError
- type ControllerProcessor
- type DummyControllerProcessor
- type ErrorResponse
- type HandlerFunc
- type HttpControllerProcessor
- type Logger
- type Options
- type ResponseWriter
- type Route
- type Router
- type Routers
- type Routes
Constants ¶
This section is empty.
Variables ¶
var ( GET_METHOD = http.MethodGet POST_METHOD = http.MethodPost PATCH_METHOD = http.MethodPatch PUT_METHOD = http.MethodPut DELETE_METHOD = http.MethodDelete )
Functions ¶
func EncodeResponse ¶
func EncodeResponse(s interface{}, err error, w http.ResponseWriter) error
EncodeResponse -
func Forward ¶
func Forward(c *Controller) http.HandlerFunc
Forward provides the means to pass a http request to an element controller
func IsRetryable ¶
IsRetryable returns true and the retry delay if ANY errors emanating from the supplied error is an ec.ControllerError that is Retryable, and false otherwise.
func NewErrorResponse ¶
func NewErrorResponse(e *ControllerError, v interface{}) (s interface{})
New Error Response - Returns encoded byte stream for responding to an http request with an error. This provides a well defined response body for all unsuccessful element controller requests.
func Reject ¶
func Reject(c *Controller) http.HandlerFunc
Reject will refuse any and all requests received by the element controller
Types ¶
type Controller ¶
type Controller struct { Name string Port int Version string Routers Routers Log Logger // contains filtered or unexported fields }
Controller -
func NewController ¶
func NewController(name string, port int, version string, routers Routers) *Controller
func (*Controller) Attach ¶
func (c *Controller) Attach(router *mux.Router, handlerFunc HandlerFunc)
Attach - Attach this controller to a existing router mux with the provided handler function This will add the element controller's defined routes, but will override the prefered route handler - allowing for interception of predefiend routes.
func (*Controller) Close ¶
func (c *Controller) Close()
func (*Controller) Init ¶
func (c *Controller) Init(opts *Options) error
Initialize an element controller with the given options, or nil for default
func (*Controller) Run ¶
func (c *Controller) Run() error
Run - Run a controller with standard behavior - that is with GRPC server and request handling that operates by unpacking the GRPC request and forwarding it to the element controller's handlers.
func (*Controller) Send ¶
func (c *Controller) Send(w http.ResponseWriter, r *http.Request)
Send a request to the element controller
func (*Controller) WithLogger ¶
func (ctrl *Controller) WithLogger(log Logger) *Controller
type ControllerError ¶
type ControllerError struct { Event interface{} // contains filtered or unexported fields }
func NewControllerError ¶
func NewControllerError(sc int) *ControllerError
func NewErrBadRequest ¶
func NewErrBadRequest() *ControllerError
func NewErrInternalServerError ¶
func NewErrInternalServerError() *ControllerError
func NewErrNotAcceptable ¶
func NewErrNotAcceptable() *ControllerError
func NewErrNotFound ¶
func NewErrNotFound() *ControllerError
func NewErrNotImplemented ¶
func NewErrNotImplemented() *ControllerError
func NewErrorNotReady ¶
func NewErrorNotReady() *ControllerError
NewErr** Functions will allocate a controller error for the specific type of error. Error details can be added through the use of WithError(err) and WithCause(string) methods
func (*ControllerError) Cause ¶
func (e *ControllerError) Cause() string
func (*ControllerError) Error ¶
func (e *ControllerError) Error() string
func (*ControllerError) IsRetryable ¶
func (e *ControllerError) IsRetryable() bool
func (*ControllerError) ResourceType ¶
func (e *ControllerError) ResourceType() string
func (*ControllerError) RetryDelay ¶
func (e *ControllerError) RetryDelay() time.Duration
func (*ControllerError) StatusCode ¶
func (e *ControllerError) StatusCode() int
func (*ControllerError) Unwrap ¶
func (e *ControllerError) Unwrap() error
func (*ControllerError) WithCause ¶
func (e *ControllerError) WithCause(cause string) *ControllerError
func (*ControllerError) WithError ¶
func (e *ControllerError) WithError(err error) *ControllerError
func (*ControllerError) WithEvent ¶
func (e *ControllerError) WithEvent(event interface{}) *ControllerError
func (*ControllerError) WithResourceType ¶
func (e *ControllerError) WithResourceType(t string) *ControllerError
func (*ControllerError) WithRetryDelay ¶
func (e *ControllerError) WithRetryDelay(delay time.Duration) *ControllerError
type ControllerProcessor ¶
type ControllerProcessor interface { Run(c *Controller, options Options) error Send(c *Controller, w http.ResponseWriter, r *http.Request) Close() }
func NewControllerProcessor ¶
func NewControllerProcessor(http bool) ControllerProcessor
type DummyControllerProcessor ¶
type DummyControllerProcessor struct{}
Dummy Controller Processor is one that does nothing, Use this processor type when you have no desire to run a controller as GRPC or HTTP.
func (*DummyControllerProcessor) Close ¶
func (*DummyControllerProcessor) Close()
func (*DummyControllerProcessor) Run ¶
func (*DummyControllerProcessor) Run(c *Controller, options Options) error
func (*DummyControllerProcessor) Send ¶
func (*DummyControllerProcessor) Send(c *Controller, w http.ResponseWriter, r *http.Request)
type ErrorResponse ¶
type HandlerFunc ¶
type HandlerFunc func(c *Controller) http.HandlerFunc
HandlerFunc defines an http handler for a controller's routes. By default the controller's routers define handlers, but by using a custom global handler function one can override this behavior.
type HttpControllerProcessor ¶
type HttpControllerProcessor struct {
// contains filtered or unexported fields
}
func (*HttpControllerProcessor) Close ¶
func (p *HttpControllerProcessor) Close()
func (*HttpControllerProcessor) Run ¶
func (p *HttpControllerProcessor) Run(c *Controller, options Options) error
func (*HttpControllerProcessor) Send ¶
func (p *HttpControllerProcessor) Send(c *Controller, w http.ResponseWriter, r *http.Request)
type Options ¶
Options -
func NewDefaultOptions ¶
func NewDefaultOptions() *Options
func NewDefaultTestOptions ¶
func NewDefaultTestOptions() *Options
type ResponseWriter ¶
ResponseWriter -
func NewResponseWriter ¶
func NewResponseWriter() *ResponseWriter
func (*ResponseWriter) Header ¶
func (r *ResponseWriter) Header() http.Header
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(code int)
type Route ¶
type Route struct { Name string Method string Path string HandlerFunc http.HandlerFunc }
Route -