context

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const EncodingGob = "Gob"

EncodingGob is the Gob Input encoding string for c.Requester

View Source
const EncodingJSON = "JSON"

EncodingJSON is the JSON Input encoding string for c.Requester

View Source
const MethodPostGob = "POST-GOB"

MethodPostGob is the HTTP Method string to enable Gob encoding for a POST request

View Source
const MethodPutGob = "PUT-GOB"

MethodPutGob is the HTTP Method string to enable Gob encoding for a POST request

Variables

This section is empty.

Functions

func DecodeEMFError

func DecodeEMFError(r io.Reader, eh errors.EMFErrorHandler) (e *errors.EMFErrorType)

DecodeEMFError is a helper function to read a request body and parse it into a EMFErrorType object or return an error, also as a EMFErrorType

func NewEMFErrorHandler

func NewEMFErrorHandler(c echo.Context, isDebug bool, opts ...errors.HandlerOption) (eh *errors.EMFErrorHandlerType)

NewEMFErrorHandler is a variadic constructor for a EMFErrorHandler.

Types

type Client

type Client interface {
	Do(req *http.Request) (res *http.Response, err error)
}

Client is an interface that mirrors the http.Client interface

type EMFContext

type EMFContext interface {
	echo.Context
	LoggerlessRequestHandler
	GetClaim(claim string) (c string, err error)
	GetRequestID() string
	GetRequestHandler() RequestHandler
	GetLimitAndOffset() (limit int, offset int, err error)
	GetRequestLimited(domain, path string) (req *http.Request, err error)
}

EMFContext is the Interface which is passed into each EMF request handler as part of each request

type EMFContextType

type EMFContextType struct {
	echo.Context
	RequestHandler
}

EMFContextType is the default implementation of the EMFContext interface

func NewEMFContext

func NewEMFContext(c echo.Context, cfg configurer.ConfigReader, opts ...Option) (ctx *EMFContextType)

NewEMFContext is a variadic constructor for a EMFContext.

func (*EMFContextType) ErrorHandler

func (ctx *EMFContextType) ErrorHandler() errors.EMFErrorHandler

ErrorHandler is a helper function to make an ErrorHandler object from the Context and return it

func (*EMFContextType) GetClaim

func (ctx *EMFContextType) GetClaim(claim string) (c string, err error)

GetClaim is a helper function to handle type and map checking for JWT Claims

func (*EMFContextType) GetLimitAndOffset

func (ctx *EMFContextType) GetLimitAndOffset() (limit int, offset int, err error)

GetLimitAndOffset is a helper function to parse limit and offset query parameters and return them

func (*EMFContextType) GetRequestHandler

func (ctx *EMFContextType) GetRequestHandler() RequestHandler

GetRequestHandler is a getter for the RequestHandler object embedded in the context

func (*EMFContextType) GetRequestID

func (ctx *EMFContextType) GetRequestID() string

GetRequestID is a helper function to expose the RequestID Header

func (*EMFContextType) GetRequestLimited

func (ctx *EMFContextType) GetRequestLimited(domain, path string) (req *http.Request, err error)

GetRequestLimited is the method to set up a HTTP Get request with no body and a limit Query Parameter

func (*EMFContextType) IsDebug

func (ctx *EMFContextType) IsDebug() bool

IsDebug is a helper function to provide access to the Debug Mode config flag

func (*EMFContextType) Logger

func (ctx *EMFContextType) Logger() echo.Logger

Logger is wrapper to disambiguate the Logger method

func (*EMFContextType) NewError

func (ctx *EMFContextType) NewError(code string, data map[string]interface{}, errors ...error) error

NewError is a helper function to wrap ErrorHandler.NewError

type LoggerlessRequestHandler

type LoggerlessRequestHandler interface {
	Requester(method, component, path string, input, output interface{}) error
	InitRequest(
		encodingType string, method string, domain string, path string, input interface{},
	) (req *http.Request, err error)
	GetRequest(component, path string) (*http.Request, error)
	JSONRequest(method, component, path string, input interface{}) (*http.Request, error)
	GobRequest(method, component, path string, input interface{}) (*http.Request, error)
	SendRequest(request *http.Request, output interface{}) error
	Header() http.Header
	GetDomain(component string) (domain string)
	IsDebug() bool
	ErrorHandler() errors.EMFErrorHandler
	NewError(code string, data map[string]interface{}, errors ...error) error
	GetDefaultLimit() (limit int)
	GetMaxLimit() (limit int)
}

LoggerlessRequestHandler is the minimum method set for the Requester family of functions

type Option

type Option func(*EMFContextType)

Option provides the client a callback that is used to dynamically specify attributes for a EMFContext.

func WithContextClient

func WithContextClient(client *http.Client) Option

WithContextClient is used to specify the HTTP Client for the Requester to use.

func WithRequestHandler

func WithRequestHandler(rh RequestHandler) Option

WithRequestHandler is used to modify the default RequestHandler object

type RHOption

type RHOption func(*RequestHandlerType)

RHOption provides the client a callback that is used to dynamically specify attributes for a RequestHandler.

func WithDebugMode

func WithDebugMode() RHOption

WithDebugMode enables debug mode on the RequestHandler

func WithHTTPClient

func WithHTTPClient(client Client) RHOption

WithHTTPClient is used for specifying the HTTP Client for the Requester to use.

func WithHeaders

func WithHeaders(headers http.Header) RHOption

WithHeaders configures the Authorization and other HTTP headers for a requestHandler

type RequestHandler

type RequestHandler interface {
	Logger() echo.Logger
	LoggerlessRequestHandler
}

RequestHandler is the minimum method set for the Requester family of functions

type RequestHandlerType

type RequestHandlerType struct {
	// contains filtered or unexported fields
}

RequestHandlerType is the minimum struct for sending requests with Requester

func NewRequestHandler

func NewRequestHandler(cfg configurer.ConfigReader, logger echo.Logger, opts ...RHOption) (rh *RequestHandlerType)

NewRequestHandler is a variadic constructor for a RequestHandler.

func (RequestHandlerType) ErrorHandler

func (rh RequestHandlerType) ErrorHandler() errors.EMFErrorHandler

ErrorHandler is a helper function to make an ErrorHandler object from the Context and return it

func (RequestHandlerType) GetDefaultLimit

func (rh RequestHandlerType) GetDefaultLimit() (limit int)

GetDefaultLimit is a helper function to expose fetching the default limit from the config file

func (RequestHandlerType) GetDomain

func (rh RequestHandlerType) GetDomain(component string) (domain string)

GetDomain is a helper function to expose fetching domains from the config file

func (RequestHandlerType) GetMaxLimit

func (rh RequestHandlerType) GetMaxLimit() (limit int)

GetMaxLimit is a helper function to expose fetching the maximum limit from the config file

func (RequestHandlerType) GetRequest

func (rh RequestHandlerType) GetRequest(domain, path string) (req *http.Request, err error)

GetRequest is the method to set up a HTTP Get request with no body

func (RequestHandlerType) GobRequest

func (rh RequestHandlerType) GobRequest(
	method, domain, path string,
	input interface{},
) (req *http.Request, err error)

GobRequest is the method to set up a Gob-encoded HTTP Request

func (RequestHandlerType) Header

func (rh RequestHandlerType) Header() http.Header

Header is a helper function to expose the http.Header object

func (RequestHandlerType) InitRequest

func (rh RequestHandlerType) InitRequest(
	encodingType string,
	method string,
	domain string,
	path string,
	input interface{},
) (req *http.Request, err error)

InitRequest is the method to initialize any HTTP request for use with rh.SendRequest

func (RequestHandlerType) IsDebug

func (rh RequestHandlerType) IsDebug() bool

IsDebug is a helper function to provide access to the Debug Mode config flag

func (RequestHandlerType) JSONRequest

func (rh RequestHandlerType) JSONRequest(
	method, domain, path string,
	input interface{},
) (req *http.Request, err error)

JSONRequest is the method to set up a JSON-encoded HTTP Request

func (RequestHandlerType) Logger

func (rh RequestHandlerType) Logger() echo.Logger

Logger is a helper function to wrap ErrorHandler.Logger

func (RequestHandlerType) NewError

func (rh RequestHandlerType) NewError(code string, data map[string]interface{}, errors ...error) error

NewError is a helper function to wrap ErrorHandler.NewError

func (RequestHandlerType) Requester

func (rh RequestHandlerType) Requester(
	method string,
	component string,
	path string,
	input interface{},
	output interface{},
) (err error)

Requester is a method to send HTTP client requests to other components Uses the same interface as before, now with modular request generation

func (RequestHandlerType) SendRequest

func (rh RequestHandlerType) SendRequest(
	req *http.Request,
	output interface{},
) (err error)

SendRequest is a method to send HTTP client requests to other components

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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