Skip to content

proposal: Allow const values to be changed through build flags before compilation #22706

@akamensky

Description

@akamensky

I often find myself in need to define some value that should never ever change during the application runtime (e.g. release version). Idiomatically this supposed to be a const, however if I need to set value to it compile-time in Go1.x I am restricted to using var only, which often makes no sense (as in example with release version)

Currently var value can be assigned at linking stage by passing -ldflags "-X main.varname=varval".

I propose to allow setting constants during compile time in same or similar manner.

From my perspective it looks as this won't be a backward compatibility breaking change, so it would be possible to implement in Go1.x (otherwise, perhaps, this can be moved to Go2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions