github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/cluster/shared/actors.go (about) 1 package shared 2 3 import "github.com/AsynkronIT/protoactor-go/cluster" 4 5 // a Go struct implementing the Hello interface 6 type hello struct { 7 cluster.Grain 8 } 9 10 func (*hello) Terminate() {} 11 12 func (h *hello) SayHello(r *HelloRequest, ctx cluster.GrainContext) (*HelloResponse, error) { 13 return &HelloResponse{Message: "hello " + r.Name + " from " + h.ID()}, nil 14 } 15 16 func (*hello) Add(r *AddRequest, ctx cluster.GrainContext) (*AddResponse, error) { 17 return &AddResponse{Result: r.A + r.B}, nil 18 } 19 20 func (*hello) VoidFunc(r *AddRequest, ctx cluster.GrainContext) (*Unit, error) { 21 return &Unit{}, nil 22 } 23 24 func init() { 25 // apply DI and setup logic 26 HelloFactory(func() Hello { return &hello{} }) 27 }