Define at compile
• 1 min read
To define a constant at build time you can use a compiler flag like:
go build -ldflags="-X 'package_path.key=value'"
and then consume it like
package package_path
var (
key = "default_value"
)
func main() {
fmt.println(key)
}