payload

package
v0.0.0-...-c29a6f0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownHandler = HandlerType("")

UnknownHandler is returned when the payload handler is unknown

Variables

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

type HandlerType

type HandlerType string

HandlerType identifies a handler type by name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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