Skip to content

Commit

Permalink
rename to rein.go
Browse files Browse the repository at this point in the history
Signed-off-by: steviebps <stephenwodecki@gmail.com>
  • Loading branch information
steviebps committed Sep 10, 2021
1 parent c1d7a9d commit d5688b8
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions pkg/config.go → pkg/rein.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ import (
"golang.org/x/mod/semver"
)

type Config struct {
type config struct {
rootChamber Chamber
configPaths []string
defaultVersion string
configFileUsed string
}

var config *Config
var c *config

func init() {
config = newConfig()
c = newConfig()
}

func newConfig() *Config {
return &Config{}
func newConfig() *config {
return &config{}
}

// SetVersion sets the version to use for the current config
func SetVersion(version string) error { return config.SetVersion(version) }
func SetVersion(version string) error { return c.SetVersion(version) }

func (cfg *Config) SetVersion(version string) error {
func (cfg *config) SetVersion(version string) error {
if isValidVersion := semver.IsValid(version); !isValidVersion {
return fmt.Errorf("%q is not a valid semantic version", version)
}
Expand All @@ -42,25 +42,25 @@ func (cfg *Config) SetVersion(version string) error {
}

// AddConfigPath adds a file path to be look for the config when initializing
func AddConfigPath(path string) error { return config.AddConfigPath(path) }
func AddConfigPath(path string) error { return c.AddConfigPath(path) }

func (cfg *Config) AddConfigPath(filePath string) error {
func (cfg *config) AddConfigPath(filePath string) error {
if filePath == "" {
return errors.New("Config path cannot be empty")
return errors.New("config path cannot be empty")
}

if path.Ext(filePath) != ".json" {
return fmt.Errorf("%q is not an acceptable file extension. Please use JSON", filePath)
}

cfg.configPaths = append(config.configPaths, filePath)
cfg.configPaths = append(c.configPaths, filePath)
return nil
}

// ReadInConfig attempts to read in the first valid file from all of the config files added by AddConfigPath
func ReadInConfig() error { return config.ReadInConfig() }
func ReadInConfig() error { return c.ReadInConfig() }

func (cfg *Config) ReadInConfig() error {
func (cfg *config) ReadInConfig() error {
var rc io.ReadCloser
var err error

Expand Down Expand Up @@ -96,10 +96,10 @@ func (cfg *Config) ReadInConfig() error {

// BoolValue retrieves a bool by the key of the toggle and takes a default value if it does not exist
func BoolValue(toggleKey string, defaultValue bool) bool {
return config.BoolValue(toggleKey, defaultValue)
return c.BoolValue(toggleKey, defaultValue)
}

func (cfg *Config) BoolValue(toggleKey string, defaultValue bool) bool {
func (cfg *config) BoolValue(toggleKey string, defaultValue bool) bool {
cBool, ok := cfg.rootChamber.GetToggleValue(toggleKey, cfg.defaultVersion).(bool)
if !ok {
return defaultValue
Expand All @@ -110,10 +110,10 @@ func (cfg *Config) BoolValue(toggleKey string, defaultValue bool) bool {

// StringValue retrieves a string by the key of the toggle and takes a default value if it does not exist
func StringValue(toggleKey string, defaultValue string) string {
return config.StringValue(toggleKey, defaultValue)
return c.StringValue(toggleKey, defaultValue)
}

func (cfg *Config) StringValue(toggleKey string, defaultValue string) string {
func (cfg *config) StringValue(toggleKey string, defaultValue string) string {
cStr, ok := cfg.rootChamber.GetToggleValue(toggleKey, cfg.defaultVersion).(string)
if !ok {
return defaultValue
Expand All @@ -124,10 +124,10 @@ func (cfg *Config) StringValue(toggleKey string, defaultValue string) string {

// Float64Value retrieves a float64 by the key of the toggle and takes a default value if it does not exist
func Float64Value(toggleKey string, defaultValue float64) float64 {
return config.Float64Value(toggleKey, defaultValue)
return c.Float64Value(toggleKey, defaultValue)
}

func (cfg *Config) Float64Value(toggleKey string, defaultValue float64) float64 {
func (cfg *config) Float64Value(toggleKey string, defaultValue float64) float64 {
cFloat64, ok := cfg.rootChamber.GetToggleValue(toggleKey, cfg.defaultVersion).(float64)
if !ok {
return defaultValue
Expand Down

0 comments on commit d5688b8

Please sign in to comment.