Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: idiomatic variable name #1321

Closed
jtblin opened this issue Mar 14, 2016 · 3 comments
Closed

Go: idiomatic variable name #1321

jtblin opened this issue Mar 14, 2016 · 3 comments
Labels

Comments

@jtblin
Copy link

jtblin commented Mar 14, 2016

It isn't a major issue but if I have a field name id in my definition, the Go code which will be generated will set the field as Id instead of ID like for idiomatic Go code. Is there a way to hint to the compiler what the variable should be in a specific language so that it stays idiomatic to this language?

Example definition

// Job represents a job definition
message Job {
    string id = 1;
}

Example generated code

// Job represents a job definition
type DeploymentJob struct {
    Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}

If we could do something like

// Job represents a job definition
message Job {
    string id = 1; `go:"ID"`
}

which would then generate

// Job represents a job definition
type DeploymentJob struct {
    ID string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
}
@xfxyjwf
Copy link
Contributor

xfxyjwf commented Mar 19, 2016

Not familiar with Go, but this seems to be the intended behavior to me. If you name a field "foo", wouldn't the Go field be named "Foo"?

@jtblin
Copy link
Author

jtblin commented Mar 19, 2016

Yes you're right for most of the terms but for others e.g. ID, URL, IP, API Go uses uppercase.

@haberman
Copy link
Member

The decision from the Go guys in golang/protobuf#156 is to keep the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants