mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/envflag: add -envflag.prefix
for setting optional prefix for environment vars
This commit is contained in:
parent
e6e321f542
commit
b47444e69d
1 changed files with 8 additions and 4 deletions
|
@ -7,9 +7,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var enable = flag.Bool("envflag.enable", false, "Whether to enable reading flags from environment variables additionally to command line. "+
|
var (
|
||||||
"Command line flag values have priority over values from environment vars. "+
|
enable = flag.Bool("envflag.enable", false, "Whether to enable reading flags from environment variables additionally to command line. "+
|
||||||
"Flags are read only from command line if this flag isn't set")
|
"Command line flag values have priority over values from environment vars. "+
|
||||||
|
"Flags are read only from command line if this flag isn't set")
|
||||||
|
prefix = flag.String("envflag.prefix", "", "Prefix for environment variables if -envflag.enable is set")
|
||||||
|
)
|
||||||
|
|
||||||
// Parse parses environment vars and command-line flags.
|
// Parse parses environment vars and command-line flags.
|
||||||
//
|
//
|
||||||
|
@ -48,5 +51,6 @@ func Parse() {
|
||||||
func getEnvFlagName(s string) string {
|
func getEnvFlagName(s string) string {
|
||||||
// Substitute dots with underscores, since env var names cannot contain dots.
|
// Substitute dots with underscores, since env var names cannot contain dots.
|
||||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/311#issuecomment-586354129 for details.
|
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/311#issuecomment-586354129 for details.
|
||||||
return strings.ReplaceAll(s, ".", "_")
|
s = strings.ReplaceAll(s, ".", "_")
|
||||||
|
return *prefix + s
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue