Documentation ¶
Index ¶
Constants ¶
const UnknownHandler = HandlerType("")
UnknownHandler is returned when the payload handler is unknown
Variables ¶
var ( ErrNoType = errors.NewWithStatus(http.StatusBadRequest, "no handler type") ErrInvalidType = errors.NewWithStatus(http.StatusBadRequest, "invalid handler type") ErrAlreadyRegistered = errors.NewWithStatus(http.StatusInternalServerError, "handler type already registered") )
Common errors
Functions ¶
func MustRegisterType ¶
func MustRegisterType(name HandlerType, h Handler)
MustRegisterType registers a new handler type. It panics if the handler type is already registered
func RegisterType ¶
func RegisterType(name HandlerType, h Handler) error
RegisterType registers a new handler type. Each handler type must have a unique name
Types ¶
type Handler ¶
type Handler interface { // Parse should parse the payload and return the extracted value // or an error Parse(payload []byte, cfg HandlerSpec) (interface{}, error) }
Handler is capable of parsing and extracting data from a given payload
type HandlerSpec ¶
type HandlerSpec map[string]interface{}
HandlerSpec defines the handler used to parse a given payload
func (HandlerSpec) GetInt ¶
func (h HandlerSpec) GetInt(key string) (int, bool, bool)
GetInt returns an integer from the HandlerSpec with the specified key The return values represent the number, if the key was set and if the key was actually a number.
Example:
value, keyWasPresent, keyWasNumber := h.GetInt("port")
func (HandlerSpec) Handler ¶
func (h HandlerSpec) Handler() (Handler, error)
Handler returns the handler specified by this spec
func (HandlerSpec) Parse ¶
func (h HandlerSpec) Parse(payload []byte) (res interface{}, err error)
Parse tries to parse the given payload
func (HandlerSpec) Type ¶
func (h HandlerSpec) Type() (HandlerType, error)
Type returns the type of the handler