github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/receivepipeline/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 console "github.com/AsynkronIT/goconsole" 7 "github.com/AsynkronIT/protoactor-go/actor" 8 "github.com/AsynkronIT/protoactor-go/actor/middleware" 9 ) 10 11 type hello struct{ Who string } 12 13 func receive(context actor.Context) { 14 switch msg := context.Message().(type) { 15 case *hello: 16 fmt.Printf("Hello %v\n", msg.Who) 17 } 18 } 19 20 func main() { 21 rootContext := actor.EmptyRootContext 22 props := actor.PropsFromFunc(receive).WithReceiverMiddleware(middleware.Logger) 23 pid := rootContext.Spawn(props) 24 rootContext.Send(pid, &hello{Who: "Roger"}) 25 console.ReadLine() 26 }