-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mrsoftware/feature/events
refactor and add event system
- Loading branch information
Showing
7 changed files
with
285 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package vabastegi | ||
|
||
import "time" | ||
|
||
// Event is what Vabastegi event look like. | ||
type Event interface { | ||
event() // it's private to prevent outside implementation. | ||
} | ||
|
||
// EventHandlers is list of EventHandler. | ||
type EventHandlers []EventHandler | ||
|
||
// Publish passed event using event handlers. | ||
func (e EventHandlers) Publish(event Event) { | ||
for _, handler := range e { | ||
handler.OnEvent(event) | ||
} | ||
} | ||
|
||
// EventHandler used if you need to handle the events. | ||
type EventHandler interface { | ||
OnEvent(event Event) | ||
} | ||
|
||
func (p *OnBuildsExecuting) event() {} | ||
func (p *OnBuildsExecuted) event() {} | ||
func (p *OnBuildExecuting) event() {} | ||
func (p *OnBuildExecuted) event() {} | ||
func (p *OnShutdownExecuting) event() {} | ||
func (p *OnShutdownExecuted) event() {} | ||
func (p *OnApplicationShutdownExecuting) event() {} | ||
func (p *OnApplicationShutdownExecuted) event() {} | ||
func (p *OnLog) event() {} | ||
|
||
// OnBuildsExecuting is emitted before a Builds is executed. | ||
type OnBuildsExecuting struct { | ||
// BuildAt is the time build happened. | ||
BuildAt time.Time | ||
} | ||
|
||
// OnBuildsExecuted is emitted after a Builds has been executed. | ||
type OnBuildsExecuted struct { | ||
// Runtime specifies how long it took to run this hook. | ||
Runtime time.Duration | ||
|
||
// Err is non-nil if the hook failed to execute. | ||
Err error | ||
} | ||
|
||
// OnBuildExecuting is emitted before a Build is executed. | ||
type OnBuildExecuting struct { | ||
// BuildAt is the time build happened. | ||
BuildAt time.Time | ||
|
||
// ProviderName is the name of the function that will be executed. | ||
ProviderName string | ||
|
||
// CallerPath is the path of provider if from. | ||
CallerPath string | ||
} | ||
|
||
// OnBuildExecuted is emitted after a Provider has been executed. | ||
type OnBuildExecuted struct { | ||
// ProviderName is the name of the function that was executed. | ||
ProviderName string | ||
|
||
// CallerPath is the path of provider if from. | ||
CallerPath string | ||
|
||
// Runtime specifies how long it took to run this hook. | ||
Runtime time.Duration | ||
|
||
// Err is non-nil if the hook failed to execute. | ||
Err error | ||
} | ||
|
||
// OnShutdownExecuting is emitted before a Shutdown is executed. | ||
type OnShutdownExecuting struct { | ||
// ShutdownAt is the time shutdown happened. | ||
ShutdownAt time.Time | ||
|
||
// ProviderName is the name of the function that will be executed. | ||
ProviderName string | ||
|
||
// CallerPath is the path of provider if from. | ||
CallerPath string | ||
} | ||
|
||
// OnShutdownExecuted is emitted after a Shutdown has been executed. | ||
type OnShutdownExecuted struct { | ||
// ProviderName is the name of the function that was executed. | ||
ProviderName string | ||
|
||
// CallerPath is the path of provider if from. | ||
CallerPath string | ||
|
||
// Runtime specifies how long it took to run this hook. | ||
Runtime time.Duration | ||
|
||
// Err is non-nil if the hook failed to execute. | ||
Err error | ||
} | ||
|
||
// OnApplicationShutdownExecuting is emitted before the application Shutdown is executed. | ||
type OnApplicationShutdownExecuting struct { | ||
// ShutdownAt is the time shutdown happened. | ||
ShutdownAt time.Time | ||
|
||
// Reason is the reason for shutdown the application. | ||
Reason string | ||
} | ||
|
||
// OnApplicationShutdownExecuted is emitted after the application Shutdown has been executed. | ||
type OnApplicationShutdownExecuted struct { | ||
// Reason is the reason for shutdown the application. | ||
Reason string | ||
|
||
// Runtime specifies how long it took to run this hook. | ||
Runtime time.Duration | ||
|
||
// Err is non-nil if the hook failed to execute. | ||
Err error | ||
} | ||
|
||
// OnLog is used if a log event is sent. | ||
type OnLog struct { | ||
LogAt time.Time | ||
Level logLevel | ||
Message string | ||
Args []interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= | ||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/mrsoftware/errors v0.1.0 h1:5MSHsrsqlBMPbNzwobVt39IpgsVee7LuSe+n8aQWPsI= | ||
github.com/mrsoftware/errors v0.1.0/go.mod h1:iHqx83gamUM9jhiV/rWZuVZe54NVqtqkIDnvZHywSM8= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.