Sobes.tech
Junior — Middle

How to specify in gRPC that a certain field is not intended for use by the client?

sobes.tech AI

Answer from AI

In gRPC, to indicate that a specific field is not intended for client use, you can use the option [(google.api.field_behavior) = OUTPUT_ONLY] in the protobuf message definition. This serves as a hint that the field is filled by the server and should not be set by the client.

Example in protobuf:

import "google/api/field_behavior.proto";

message User {
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  string name = 2;
}

In Go code, this does not impose compile-time restrictions but serves as documentation and may be considered by code generation or validation tools.

If special options are not used, agreements about who should set the field are maintained at the protocol and documentation level.

How to specify in gRPC that a certain field is not… - sobes.tech