Mercurial > hg > Docker > GRPCTest
view server.go @ 7:4a4b9a3837c7 default tip
...
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 23 May 2020 10:36:15 +0900 |
parents | 568ffe87c352 |
children |
line wrap: on
line source
package main import ( "context" "errors" "google.golang.org/grpc" "log" "net" cat "study-grpc/pb" ) type myCatService struct{} func (s *myCatService) GetMyCat(ctx context.Context, message *cat.GetMyCatMessage) (*cat.MyCatResponse, error) { switch message.TargetCat { case "tama": return &cat.MyCatResponse{ Name: "tama", Kind: "Maine Coon", }, nil case "mike": return &cat.MyCatResponse{ Name: "mike", Kind: "Norwegian Forest Cat", }, nil default: return nil, errors.New("Not Found YourCat..") } } func main() { port, err := net.Listen("tcp", ":1234") if err != nil { log.Println(err.Error()) return } s := grpc.NewServer() cat.RegisterCatServer(s, &myCatService{}) s.Serve(port) }