Add example of handling a required argument
More from: https://github.com/twitchtv/twirp/wiki/Best-Practices
This commit is contained in:
parent
9ccfd44724
commit
7c35411a0a
4
hwt.go
4
hwt.go
@ -4,11 +4,15 @@ import (
|
||||
"context"
|
||||
fmt "fmt"
|
||||
|
||||
"github.com/twitchtv/twirp"
|
||||
pb "mcquay.me/hwt/rpc/hwt"
|
||||
)
|
||||
|
||||
type Server struct{}
|
||||
|
||||
func (s *Server) Hello(ctx context.Context, req *pb.HelloReq) (*pb.HelloResp, error) {
|
||||
if req.Subject == "" {
|
||||
return nil, twirp.RequiredArgumentError("subject")
|
||||
}
|
||||
return &pb.HelloResp{Text: fmt.Sprintf("echo: %v", req.Subject)}, nil
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ service HelloWorld {
|
||||
}
|
||||
|
||||
message HelloReq {
|
||||
string subject = 1;
|
||||
string subject = 1; // required
|
||||
}
|
||||
|
||||
message HelloResp {
|
||||
string text = 1;
|
||||
string text = 1; // required
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user