Documentation
¶
Index ¶
- Constants
- Variables
- type AppProfile
- type Closer
- type Config
- func (c *Config) Build() *Godim
- func (c *Config) WithAppProfile(ap *AppProfile) *Config
- func (c *Config) WithConfigString(config string) *Config
- func (c *Config) WithConfigurationFunction(f func(key string, val reflect.Value) (interface{}, error)) *Config
- func (c *Config) WithEventSwitch(bufferSize int) *Config
- func (c *Config) WithInjectString(inject string) *Config
- type Counter
- type Emitter
- type ErrType
- type Error
- type Event
- type EventEmitter
- type EventFinalizer
- type EventInterceptor
- type EventReceiver
- type EventState
- type EventSwitch
- func (es *EventSwitch) AddEmitter(e Emitter) error
- func (es *EventSwitch) AddInterceptor(e EventInterceptor) error
- func (es *EventSwitch) AddReceiver(e EventReceiver) error
- func (es *EventSwitch) Close()
- func (es *EventSwitch) CloseGracefully()
- func (es *EventSwitch) Start()
- func (es *EventSwitch) Stop()
- func (es *EventSwitch) WithEventFinalizer(f EventFinalizer) *EventSwitch
- func (es *EventSwitch) WithIDGenerator(idg IDGenerator) *EventSwitch
- func (es *EventSwitch) WithSeed(seed uint64) *EventSwitch
- type Godim
- func (godim *Godim) CloseApp() error
- func (godim *Godim) CloseAppGracefully() error
- func (godim *Godim) Declare(label string, o ...interface{}) error
- func (godim *Godim) DeclareDefault(o ...interface{}) error
- func (godim *Godim) GetStruct(label, key string) interface{}
- func (godim *Godim) RunApp() error
- type IDGenerator
- type Identifier
- type Initializer
- type Prioritizer
- type Profile
- type Registry
- type TagConfig
Constants ¶
const Version = "0.5.0-alpha"
Version is the current godim version
Variables ¶
var DefaultProfile = Profile{ // contains filtered or unexported fields }
DefaultProfile specific default profile that allows anything to be injected into anything
Functions ¶
This section is empty.
Types ¶
type AppProfile ¶
type AppProfile struct {
// contains filtered or unexported fields
}
AppProfile represents the differents Profile of your application see @Profile for Profile detail
func HTTPAppProfile ¶
func HTTPAppProfile() *AppProfile
HTTPAppProfile return a less strict http profile based on :
- handler : manage http input and can call services
- service : manage business logic and can call repositories and other services
- repository : manage data access
func StrictHTTPAppProfile ¶
func StrictHTTPAppProfile() *AppProfile
StrictHTTPAppProfile return a strict http profile based on :
- handler : manage http input and can call service
- service : manage business logic and can call repositories
- repository : manage data access
- driver : manage resource driver
func (*AppProfile) AddProfile ¶
func (ap *AppProfile) AddProfile(p *Profile) error
AddProfile add a profile
func (*AppProfile) AddProfileDef ¶
func (ap *AppProfile) AddProfileDef(name string, injectIn ...string) error
AddProfileDef add a new profile definition
- name name to use in injection
- injectIn where it can be injected
type Closer ¶
type Closer interface {
OnClose() error
}
Closer interface to implement if you need specific closing method
OnClose will be called on close phase
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config struct for Godim
func (*Config) WithAppProfile ¶
func (c *Config) WithAppProfile(ap *AppProfile) *Config
WithAppProfile declare the app profile to use
func (*Config) WithConfigString ¶
WithConfigString use a new config string
func (*Config) WithConfigurationFunction ¶
func (c *Config) WithConfigurationFunction(f func(key string, val reflect.Value) (interface{}, error)) *Config
WithConfigurationFunction declare your configuration function
func (*Config) WithEventSwitch ¶
WithEventSwitch start an event switch with godim
func (*Config) WithInjectString ¶
WithInjectString use a new inject string
type ErrType ¶
type ErrType uint64
ErrType base type for Error Type
const ( // ErrTypeInjection happens in injection phase failure ErrTypeInjection ErrType = 1 << 63 // ErrTypeProfile happens in profile definition failure ErrTypeProfile ErrType = 1 << 62 // ErrTypeRegistry happens in internal registry failure ErrTypeRegistry ErrType = 1 << 61 // ErrTypeGodim happens in internal godim failure ErrTypeGodim ErrType = 1 << 60 // ErrTypeEvent happens in internal event switch ErrTypeEvent ErrType = 1 << 59 // ErrTypeAny for any other kind of errors ErrTypeAny ErrType = 1 << 1 )
type Error ¶
Error main godim error struct
func (*Error) SetErrType ¶
SetErrType sets the error's type.
type Event ¶
type Event struct {
Type string
Payload map[string]interface{}
// contains filtered or unexported fields
}
Event an Event can be transmitted from an Emitter to any Receiver. It's not yet immutable but needs to be considered as they can be concurrently accessed. The id is set internally and can be overridden only if another generator is used. The metadata can be set with AddMetadata(key string, value interface{}) and can be retrieved with GetMetadata(key string). An event is locked after "interceptor" phase which means its metadata cannot be modified through previous methods.
func (*Event) Abort ¶
func (event *Event) Abort(current EventInterceptor, reason string)
Abort stop the processing of the event. This method could be called from any interceptor. A locked event cannot be aborted.
func (*Event) AddMetadata ¶
AddMetadata add a key value pair of metadata to the event
An error will occur if the event is locked or if the key exists already.
func (*Event) GetMetadata ¶
func (*Event) GetState ¶
func (event *Event) GetState() EventState
type EventEmitter ¶
type EventEmitter struct {
// contains filtered or unexported fields
}
func (*EventEmitter) Emit ¶
func (ee *EventEmitter) Emit(event *Event)
Emit adds metadata to the event then emit it through the channel
type EventFinalizer ¶
type EventFinalizer interface {
Finalize(*Event)
}
type EventInterceptor ¶
type EventInterceptor interface {
Identifier
Intercept(*Event) error
InterceptPriority() int
}
EventInterceptor any events handled by the EventSwitch goes through the interceptors. An interceptor can abort an Event to stop its processing beyond the interceptor itself. An interceptor must define a priority and 2 interceptors cannot have the same priority.
type EventReceiver ¶
type EventReceiver interface {
Identifier
ReceiveEvent(*Event) error
HandleEventTypes() []string
}
EventReceiver All events are treated in a choreographic pattern, asynchronously. The HandleEventTypes should return the types of event the receiver wants to handle.
type EventState ¶
type EventState int
const ( // ESEmitted the event is being processed ESEmitted EventState = iota // ESResolved the event has been successfully processed by the interceptors and the receivers ESResolved // ESAborted the event processing is stopped which means that it won't be transmitted to any receiver ESAborted // ESError the event encountered an error during its processing ESError )
type EventSwitch ¶
type EventSwitch struct {
// contains filtered or unexported fields
}
EventSwitch this is not a hub, we want a switch
func NewEventSwitch ¶
func NewEventSwitch(bufferSize int) *EventSwitch
NewEventSwitch build a new event switch
func (*EventSwitch) AddEmitter ¶
func (es *EventSwitch) AddEmitter(e Emitter) error
AddEmitter add an emitter
func (*EventSwitch) AddInterceptor ¶
func (es *EventSwitch) AddInterceptor(e EventInterceptor) error
AddInterceptor add an interceptor. An error is returned when an interceptor with the same priority is already declared.
func (*EventSwitch) AddReceiver ¶
func (es *EventSwitch) AddReceiver(e EventReceiver) error
AddReceiver add a receiver
func (*EventSwitch) Close ¶
func (es *EventSwitch) Close()
Close stop the EventEmitter then closes it channels
func (*EventSwitch) CloseGracefully ¶
func (es *EventSwitch) CloseGracefully()
CloseGracefully wait for all events to be processed then close the EventSwitch This method is blocking until the EventSwitch is stopped.
func (*EventSwitch) Start ¶
func (es *EventSwitch) Start()
Start initialize the EventSwitch and start it
func (*EventSwitch) Stop ¶
func (es *EventSwitch) Stop()
func (*EventSwitch) WithEventFinalizer ¶
func (es *EventSwitch) WithEventFinalizer(f EventFinalizer) *EventSwitch
WithEventFinalizer declare an event finalizer that will be called at the end of an event management
func (*EventSwitch) WithIDGenerator ¶
func (es *EventSwitch) WithIDGenerator(idg IDGenerator) *EventSwitch
WithIDGenerator change the id generator used.
if the switch is running, do nothing
func (*EventSwitch) WithSeed ¶
func (es *EventSwitch) WithSeed(seed uint64) *EventSwitch
WithSeed change the seed of the generator
if the switch is running, do nothing
type Godim ¶
type Godim struct {
// contains filtered or unexported fields
}
Godim is the main app controller
func (*Godim) CloseAppGracefully ¶
CloseApp close all things declared in your app
func (*Godim) DeclareDefault ¶
DeclareDefault : declare all your defaults services
type IDGenerator ¶
type Identifier ¶
type Identifier interface {
Key() string
}
Identifier interface to implement if you want to name your service.
Key is the key name that will reference it in the other service
type Initializer ¶
type Initializer interface {
OnInit() error
}
Initializer interface to implement if you need specific initialization
OnInit will be called after Injection phase
type Prioritizer ¶
type Prioritizer interface {
Priority() int
}
Prioritizer interface to implement if you want to change the initialization order of your service.
Priority is the score that will determine when this service will be instantiated comparing to the others. Default priority is 0. Lower is sooner.
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile a Profile represent an injectable type
It holds the possible dependency tree in order to validate non-cycling app ¶
injection example :
type UserService struct {
userRepository *UserRepository inject:"repository:UserRepository"
}