ec

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func IsRetryable(err error) (bool, time.Duration)

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 forwardining 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) Send

type ErrorResponse

type ErrorResponse struct {
	Status  int    `json:"status"`
	Error   string `json:"error"`
	Cause   string `json:"cause,omitempty"`
	Details string `json:"details,omitempty"`
	Model   string `json:"model,omitempty"`
}

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

type Logger

type Logger = logr.Logger

type Options

type Options struct {
	Http    bool
	Port    int
	Log     bool
	Verbose bool
}

Options -

func BindFlags

func BindFlags(fs *flag.FlagSet) *Options

func NewDefaultOptions

func NewDefaultOptions() *Options

func NewDefaultTestOptions

func NewDefaultTestOptions() *Options

type ResponseWriter

type ResponseWriter struct {
	StatusCode int
	Hdr        http.Header
	Buffer     *bytes.Buffer
}

ResponseWriter -

func NewResponseWriter

func NewResponseWriter() *ResponseWriter

func (*ResponseWriter) Header

func (r *ResponseWriter) Header() http.Header

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(b []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(code int)

type Route

type Route struct {
	Name        string
	Method      string
	Path        string
	HandlerFunc http.HandlerFunc
}

Route -

type Router

type Router interface {
	Routes() Routes

	Name() string
	Init(Logger) error
	Start() error
	Close() error
}

Router -

type Routers

type Routers []Router

Routers -

type Routes

type Routes []Route

Routes -

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL