package main import ( "context" "fmt" "github.com/go-kratos/kratos/examples/helloworld/helloworld" "github.com/go-kratos/kratos/v2/errors" ) // server is used to implement helloworld.GreeterServer. type server struct { helloworld.UnimplementedGreeterServer } // SayHello implements helloworld.GreeterServer func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { if in.Name == "error" { return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) } if in.Name == "panic" { panic("grpc panic") } return &helloworld.HelloReply{Message: fmt.Sprintf("Hello %+v", in.Name)}, nil }