-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3278 from deckhouse/featureflags-pkg
Introduce a dedicated pkg for featureflags
- Loading branch information
Showing
3 changed files
with
49 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package featureflags | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type flag struct { | ||
Name string | ||
Default bool | ||
} | ||
|
||
func (f *flag) env() string { | ||
return "DEX_" + strings.ToUpper(f.Name) | ||
} | ||
|
||
func (f *flag) Enabled() bool { | ||
raw := os.Getenv(f.env()) | ||
if raw == "" { | ||
return f.Default | ||
} | ||
|
||
res, err := strconv.ParseBool(raw) | ||
if err != nil { | ||
return f.Default | ||
} | ||
return res | ||
} | ||
|
||
func newFlag(s string, d bool) *flag { | ||
return &flag{Name: s, Default: d} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package featureflags | ||
|
||
var ( | ||
// EntEnabled enables experimental ent-based engine for the database storages. | ||
// https://entgo.io/ | ||
EntEnabled = newFlag("ent_enabled", false) | ||
|
||
// ExpandEnv can enable or disable env expansion in the config which can be useful in environments where, e.g., | ||
// $ sign is a part of the password for LDAP user. | ||
ExpandEnv = newFlag("expand_env", true) | ||
) |