1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

examples: update mod (#862)

* fix examples errors
This commit is contained in:
Tony Chen
2021-04-25 22:26:31 +08:00
committed by GitHub
parent 9806191b7f
commit 3780f70c91
17 changed files with 71 additions and 97 deletions
+9 -2
View File
@@ -20,7 +20,14 @@ func main() {
}
func callHTTP() {
client, err := transhttp.NewClient(context.Background())
client, err := transhttp.NewClient(
context.Background(),
transhttp.WithMiddleware(
middleware.Chain(
recovery.Recovery(),
),
),
)
if err != nil {
log.Fatal(err)
}
@@ -71,7 +78,7 @@ func callGRPC() {
if err != nil {
log.Printf("[grpc] SayHello error: %v\n", err)
}
if errors.IsInvalidArgument(err) {
if errors.IsBadRequest(err) {
log.Printf("[grpc] SayHello error is invalid argument: %v\n", err)
}
}
+12 -4
View File
@@ -17,6 +17,14 @@ import (
"github.com/go-kratos/kratos/v2/transport/http"
)
// go build -ldflags "-X main.Version=x.y.z"
var (
// Name is the name of the compiled software.
Name = "helloworld"
// Version is the version of the compiled software.
Version = "v1.0.0"
)
// server is used to implement helloworld.GreeterServer.
type server struct {
pb.UnimplementedGreeterServer
@@ -25,7 +33,7 @@ type server struct {
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
if in.Name == "error" {
return nil, errors.InvalidArgument("BadRequest", "invalid argument %s", in.Name)
return nil, errors.BadRequest(Name, "custom_error", fmt.Sprintf("invalid argument %s", in.Name))
}
if in.Name == "panic" {
panic("grpc panic")
@@ -42,8 +50,8 @@ func main() {
grpc.Address(":9000"),
grpc.Middleware(
middleware.Chain(
logging.Server(logging.WithLogger(logger)),
status.Server(),
logging.Server(logger),
recovery.Recovery(),
),
))
@@ -55,14 +63,14 @@ func main() {
httpSrv.HandlePrefix("/", pb.NewGreeterHandler(s,
http.Middleware(
middleware.Chain(
logging.Server(logging.WithLogger(logger)),
logging.Server(logger),
recovery.Recovery(),
),
)),
)
app := kratos.New(
kratos.Name("helloworld"),
kratos.Name(Name),
kratos.Server(
httpSrv,
grpcSrv,