github.com/godevsig/adaptiveservice@v0.9.23/examples/hello/message/message.go (about) 1 package message 2 3 import ( 4 "strings" 5 6 as "github.com/godevsig/adaptiveservice" 7 ) 8 9 // HelloRequest is the request from clients 10 type HelloRequest struct { 11 Who string 12 Question string 13 } 14 15 // HelloReply is the reply of HelloRequest to clients 16 type HelloReply struct { 17 Answer string 18 } 19 20 // Handle handles msg. 21 func (msg HelloRequest) Handle(stream as.ContextStream) (reply interface{}) { 22 answer := "I don't know" 23 24 question := strings.ToLower(msg.Question) 25 switch { 26 case strings.Contains(question, "who are you"): 27 answer = "I am hello server" 28 case strings.Contains(question, "how are you"): 29 answer = "I am good" 30 } 31 return HelloReply{answer + ", " + msg.Who} 32 } 33 34 func init() { 35 as.RegisterType(HelloRequest{}) 36 as.RegisterType(HelloReply{}) 37 }