MCPcopy
hub / github.com/grpc/grpc-go / SayHello

Method SayHello

examples/features/error_details/server/main.go:48–69  ·  view source on GitHub ↗

SayHello implements helloworld.GreeterServer

(_ context.Context, in *pb.HelloRequest)

Source from the content-addressed store, hash-verified

46
47// SayHello implements helloworld.GreeterServer
48func (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
71func main() {
72 flag.Parse()

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
WithDetailsMethod · 0.80
ErrMethod · 0.80
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected