Skip to content

Proposal: flag: add support for int32 and uint32 options #26545

@rvegas

Description

@rvegas

Currently many core libraries like grpc have configurable flags and options that are either int32 or uint32, e.g.

This forces the userland code for any configurable system to look something like this:

...
maxConcurrentStreams := f.Int("max_streams", 100, "Number of maximum concurrent streams")
f.Parse()
...
maxConcurrentConnectionsOption := grpc.MaxConcurrentStreams(uint32(maxConcurrentStreams))
...

Such casting (and any other workaround) results in error prone implementations sometimes, since the error handling has to be done by the developer, which I'm not particulary against, but it's better if we could trust Go's core flag parsing library to support and validate this.

In this manner, we could allow the implementations to simply look like this:

maxConcurrentStreams := f.Uint32("max_streams", 100, "Number of maximum concurrent streams")
f.Parse()
...
maxConcurrentConnectionsOption := grpc.MaxConcurrentStreams(maxConcurrentStreams)
...

I know it may look simple but flag already supports int, int64 and float64, so imho, adding this makes sense and allows for better looking and more secure code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeProposalWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions