-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·56 lines (45 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/AsynkronIT/goconsole"
"github.com/meeypioneer/mey-actor/actor"
"github.com/meeypioneer/mey-actor/actor/middleware"
"github.com/meeypioneer/mey-actor/plugin"
)
type myActor struct {
NameAwareHolder
}
func (state *myActor) Receive(context actor.Context) {
switch context.Message().(type) {
case *actor.Started:
//this actor have been initialized by the receive pipeline
fmt.Printf("My name is %v\n", state.name)
}
}
type NameAware interface {
SetName(name string)
}
type NameAwareHolder struct {
name string
}
func (state *NameAwareHolder) SetName(name string) {
state.name = name
}
type NamerPlugin struct{}
func (p *NamerPlugin) OnStart(ctx actor.Context) {
if p, ok := ctx.Actor().(NameAware); ok {
p.SetName("GAM")
}
}
func (p *NamerPlugin) OnOtherMessage(ctx actor.Context, usrMsg interface{}) {}
func main() {
props := actor.
FromProducer(func() actor.Actor { return &myActor{} }).
WithMiddleware(
plugin.Use(&NamerPlugin{}),
middleware.Logger,
)
pid := actor.Spawn(props)
pid.Tell("bar")
console.ReadLine()
}