SayHello implements helloworld.GreeterServer
(_ context.Context, in *pb.HelloRequest)
| 46 | |
| 47 | // SayHello implements helloworld.GreeterServer |
| 48 | func (s *server) SayHello(_ context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { |
| 49 | s.mu.Lock() |
| 50 | defer s.mu.Unlock() |
| 51 | // Track the number of times the user has been greeted. |
| 52 | s.count[in.Name]++ |
| 53 | if s.count[in.Name] > 1 { |
| 54 | st := status.New(codes.ResourceExhausted, "Request limit exceeded.") |
| 55 | ds, err := st.WithDetails( |
| 56 | &epb.QuotaFailure{ |
| 57 | Violations: []*epb.QuotaFailure_Violation{{ |
| 58 | Subject: fmt.Sprintf("name:%s", in.Name), |
| 59 | Description: "Limit one greeting per person", |
| 60 | }}, |
| 61 | }, |
| 62 | ) |
| 63 | if err != nil { |
| 64 | return nil, st.Err() |
| 65 | } |
| 66 | return nil, ds.Err() |
| 67 | } |
| 68 | return &pb.HelloReply{Message: "Hello " + in.Name}, nil |
| 69 | } |
| 70 | |
| 71 | func main() { |
| 72 | flag.Parse() |
nothing calls this directly
no test coverage detected