Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // SchemaDir holds the directory name where schemas are kept SchemaDir string )
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
Log *logrus.Logger
Handlers map[string]*HandlerWrapper
Params map[string]interface{}
// contains filtered or unexported fields
}
Application struct takes care of libraries needed to run the app, at the moment this has a single connection to nats, but in the future this will need to be a pooled connection.
func (*Application) Handler ¶
func (a *Application) Handler(subject string, handler EventHandler) *HandlerWrapper
Handler simply adds a new handler to the handlers map
func (*Application) Produce ¶
func (a *Application) Produce(subject string, obj interface{})
Produce puts the given message onto the specified topicz
func (*Application) RegisterHandlers ¶
func (a *Application) RegisterHandlers()
RegisterHandlers loops through the handlers that have been defined and starts consuming
func (*Application) Run ¶
func (a *Application) Run()
Run starts the application daemon, this also starts any consumer
func (*Application) With ¶
func (a *Application) With(key string, param interface{})
With adds a dependency into the params map
type Context ¶
type Context struct {
App *Application
Data string
Decoded interface{}
// contains filtered or unexported fields
}
Context is used to separate nats from the handlers, it abstracts the message and gives them access to the application without the need for global variables
func (*Context) MustBind ¶
func (ctx *Context) MustBind(in interface{})
MustBind ensures that the data from an event binds to the given interface
func (*Context) Unsubscribe ¶
func (ctx *Context) Unsubscribe()
Unsubscribe sends a message to the unsubscribe channel of the handler attached to the current context
type EventHandler ¶
type EventHandler func(ctx *Context)
EventHandler defines the contract for an event handler
type HandlerWrapper ¶
type HandlerWrapper struct {
Handler EventHandler
Schema *avro.Codec
// contains filtered or unexported fields
}
HandlerWrapper is used to contain an event handler and any options or settings associated with them, you can bind schemas to the wrapper which are evaluated when a message is received before they are sent to the handler.
func NewHandler ¶
func NewHandler(e EventHandler) *HandlerWrapper
NewHandler returns a new HandlerWrapper struct
func (*HandlerWrapper) Listen ¶
func (w *HandlerWrapper) Listen(ctx *Context)
Listen allows the handler to listen to the intake and unsubscribe channels
func (*HandlerWrapper) WithAvro ¶
func (w *HandlerWrapper) WithAvro(schema string)
WithAvro accepts a schema file containing an avro schema this method will panic if the file does not exist or if the file does not contain valid avro