Documentation ¶
Index ¶
- func ByAction(e eventtypes.Message) string
- func ByType(e eventtypes.Message) string
- func Monitor(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, ...) chan error
- func MonitorWithHandler(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, ...) chan error
- type Handler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByAction ¶
func ByAction(e eventtypes.Message) string
ByAction is a qualify function based on message action.
func ByType ¶
func ByType(e eventtypes.Message) string
ByType is a qualify function based on message type.
func Monitor ¶
func Monitor(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, fun func(m eventtypes.Message)) chan error
Monitor subscribes to the docker events api using engine api and will execute the specified function on each message. It will pass the specified options to the underline method (i.e Events).
Example ¶
cli, err := client.NewEnvClient() if err != nil { // Do something.. } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() errChan := Monitor(ctx, cli, types.EventsOptions{}, func(event eventtypes.Message) { fmt.Printf("%v\n", event) }) if err := <-errChan; err != nil { // Do something }
Output:
func MonitorWithHandler ¶
func MonitorWithHandler(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, handler *Handler) chan error
MonitorWithHandler subscribes to the docker events api using engine api and will pass the message to the specified Handler, that will take care of it. It will pass the specified options to the underline method (i.e Events).
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a struct holding the handlers by keys, and the function to get the key from the message.
func NewHandler ¶
func NewHandler(fun func(eventtypes.Message) string) *Handler
NewHandler creates an event handler using the specified function to qualify the message and to route it to the correct handler.
func (*Handler) Handle ¶
func (w *Handler) Handle(key string, h func(eventtypes.Message))
Handle registers a function has handler for the specified key.
func (*Handler) Watch ¶
func (w *Handler) Watch(c <-chan eventtypes.Message)
Watch ranges over the passed in event chan and processes the events based on the handlers created for a given action. To stop watching, close the event chan.