Documentation ¶
Overview ¶
Package eventbus provides a remote event bus that accepts new events via HTTP POSTs and broadcasts events via WebSockets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorsHostAndPort ¶
func CorsHostAndPort(v string) option
Configure the CORS host and port for the EventBus server. This is the host and port where JavaScript client calls are coming from.
func HostAndPort ¶
func HostAndPort(v string) option
Configure the host and port of the EventBus server.
Types ¶
type Event ¶
type Event struct { Name string `json:"name"` Data interface{} `json:"data"` Context map[string]string `json:"context"` }
Represents a single event fired by either a client or a service.
type EventStore ¶
type EventStore interface { // Write the event to the event store. Returns an error // if the event fails to write. WriteEvent(*Event) error }
Event stores are used to persist events when they are created.
type InMemoryEventStore ¶
type InMemoryEventStore struct {
Events []*Event
}
A simple in-memory event store that puts all events in an Array.
func NewInMemoryEventStore ¶
func NewInMemoryEventStore() *InMemoryEventStore
Construct a new in-memory event store. Returns a pointer to the event store.
func (*InMemoryEventStore) WriteEvent ¶
func (store *InMemoryEventStore) WriteEvent(event *Event) (err error)
Save the event in an in-memory array.
type NullEventStore ¶
type NullEventStore struct { }
Event store that simply discards events.
func NewNullEventStore ¶
func NewNullEventStore() *NullEventStore
Construct a new NullEventStore and return a pointer to it.
func (*NullEventStore) WriteEvent ¶
func (store *NullEventStore) WriteEvent(event *Event) (err error)
Silently discard the event.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
The EventBus server.
func NewServer ¶
func NewServer(opts ...option) *Server
Configure a new server that is ready to be started.
func (*Server) Start ¶
func (server *Server) Start()
Start the event bus server for handling JSON events over HTTP.
This function starts a handler on the root that is used for POST requests to construct new events. It also starts a WebSocket handler on /ws that is used for broadcasting events to the client or service.
type ServiceConfig ¶
Configuration for a service that may attach.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fileserver is a simple file server for serving up static files for the JavaScript demo.
|
Package fileserver is a simple file server for serving up static files for the JavaScript demo. |
Package middleware provides shared middleware that is used in HTTP services.
|
Package middleware provides shared middleware that is used in HTTP services. |