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

Selective usage of String method #65

Open
distributed opened this issue May 24, 2017 · 1 comment
Open

Selective usage of String method #65

distributed opened this issue May 24, 2017 · 1 comment

Comments

@distributed
Copy link

I have some Protobuf/gRPC generated types that I would like to pretty print using spew.

Some types, like enums, have String() methods generated that produce nice, readable output, for an example, see DevStatusReply_Status in the code below. For these types I prefer spew calling String() instead of formatting by itself.

Some types, structs like DevStatusReply_StatusDetails below , have a generated String() method that produces terses output. For these types I would rather have spew handle the printing by itself.

Using ConfigState.DisableMethods I can turn off and on whether spew calls the String() method, but I cannot discern between calling String() for the enums and spew pretty printing for the structs.

Is there a way I can control more finely which String()methods get called? Is there a way to work around this, except duplicating spew's code in my own program?

Code:

type DevStatusReply struct {
    Status      DevStatusReply_Status            `protobuf:"varint,4,opt,name=...`
    Details     *DevStatusReply_StatusDetails `protobuf:"bytes,8,opt,name=..."`
}

type DevStatusReply_Status int32
const (
    DevStatusReply_INVALID_STATUS DevStatusReply_Status = 0
    DevStatusReply_IDLE           DevStatusReply_Status = 1
    // and so on...
)

// prints nice string representation of enum
func (s DevStatusReply_Status) String() string { ... }

type DevStatusReply_StatusDetails struct {
   ...
}

// prints unwanted string representation of struct
func (x *DevStatusReply_StatusDetails) String() { ... }
@jrick
Copy link
Contributor

jrick commented May 24, 2017

Might want to report this to the gRPC developers so the protoc plugin can produce better output. It should be implementing GoStringer for a string representation of the Go syntax, not String.

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

No branches or pull requests

2 participants