modulepackage
0.0.0-20210717165448-98fbcdcdc673
Repository: https://github.com/timoth-y/go-eventdriver.git
Documentation: pkg.go.dev
# README

Go package for handling local communication and logic responsibility segregation in an eventual way
Usage
import (
"context"
"github.com/op/go-logging"
"github.com/spf13/viper"
"github.com/timoth-y/go-eventdriver"
)
func main() {
// First, let's initialize eventdriver package:
eventdriver.Init(
eventdriver.WithLogger(logging.MustGetLogger("eventdriver_test")),
eventdriver.WithBufferSize(viper.GetInt("event_channel_buffer_size")),
)
// Put handler somewhere in the use cases layer:
eventdriver.SubscribeHandler("example.event.occurred", func(ctx context.Context, v interface{}) error {
if payload, ok := v.(ExampleEventPayload); ok {
// Do some awesome handling of the event here
handleEvent(payload)
return nil
}
return eventdriver.ErrIncorrectPayload
})
// Emit event in any place where such event can occur:
eventdriver.EmitEvent(context.Background(), "example.event.occurred", ExampleEventPayload{
Nice: true,
})
// Shutdown event loop gracefully.
eventdriver.Close()
}
# Functions
Close stops event loop and free resources.
EmitEvent emits event for concurrent handlers.
Init performs initialisation of the EventDriver.
SubscribeChannel subscribes to given `event` and redirects its payload to returned channel.
SubscribeHandler subscribes new `handler` for given `event`.
WithBufferSize can be used to specify logger implementation for driver client.
WithLogger can be used to specify logger implementation for driver client.
# Variables
No description provided by the author
# Structs
EventDriver provides a tool for handling inner-service communication and responsibility segregation in eventual way.
EventMessage defines event message.
NopLogger is a default implementation of the Logger interface.
# Type aliases
EventHandlerFunc defines signature func for handling event.
OptionFunc is a function that configures a EventDriver client.