how to enforce case property name on proto generation for go

Viewed 23

I have a user message as such :

message User {
    string uid = 1;
}

Protobuff generates a struct as such

type User struct {
    Uid string
}

Is there a way to enforce destination case so that my user struct in Go would be like :

type User struct {
    UID string
}

So far, I can use string uID in my proto definition but it feels a bit hacky.

1 Answers

This does not seem to be supported.
As listed in golang/protobuf issue 555

By convention, naming styles are different:

  • Protos uses CamelCase for messages, groups, enums, services, and methods
  • Protos uses snake_case for fields and oneof fields
  • Protos uses SCREAMING_SNAKE_CASE for enum values
  • Go uses CamelCase for everything

So for now, uID is the best workaround.

Related