documentation
This commit is contained in:
parent
1e2b3a2e5c
commit
a161b0d68e
51
README.md
51
README.md
@ -3,7 +3,8 @@
|
||||
## How To
|
||||
|
||||
In this Example i use the generic-di package to Inject a Service into a Event.
|
||||
first you have to create some Event Handler:
|
||||
First you have to create some Event Handler and/or Effects that was fired when a Event happens.
|
||||
Then you give the Effects and the EventHandlers to a Registration to serve it.
|
||||
|
||||
services/external_service.go
|
||||
|
||||
@ -104,3 +105,51 @@ func (event *UserLoginEvent) Handle(ctx *serverevents.Context) {
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
effects/login_success_effect.go
|
||||
|
||||
```go
|
||||
package effects
|
||||
|
||||
type LoginSuccessEffect struct {}
|
||||
|
||||
func NewLoginSuccessEffect() *LoginSuccessEffect {
|
||||
return &LoginSuccessEffect{}
|
||||
}
|
||||
|
||||
// implement a Method that gives the Name of the Event to listen
|
||||
func (effect *LoginSuccessEffect) OnEvent() string {
|
||||
return "login success"
|
||||
}
|
||||
|
||||
// implement a Method to Handle the Effect triggered
|
||||
func (effect *LoginSuccessEffect) Execute(ctx *serverevents.Context) {
|
||||
// do something on login success here...
|
||||
}
|
||||
```
|
||||
|
||||
main.go
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
serverevents "git.apihub24.de/admin/server_events"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := ":8080"
|
||||
|
||||
serverevents.RegisterEvents([]serverevents.EventHandler{
|
||||
events.NewLoginEvent(),
|
||||
}, []serverevents.Effect{
|
||||
effects.NewLoginSuccessEffect(),
|
||||
}, nil)
|
||||
|
||||
log.Default().Printf("Start Server at Port %s", port)
|
||||
err := http.ListenAndServe(port, nil)
|
||||
if err != nil {
|
||||
log.Fatalf("Error on start Server: %v", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user