1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-11 13:38:46 +02:00
Tony Chen 1b13abd136
transport/http: add http route (#1029)
* add http route

* fix http context

* add HTTP middleware

Co-authored-by: longXboy <longxboyhi@gmail.com>
2021-06-12 18:30:17 +08:00

26 lines
679 B
Go

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
}