diff --git a/pkg/config.go b/pkg/rein.go similarity index 76% rename from pkg/config.go rename to pkg/rein.go index 8477808..d0112a9 100644 --- a/pkg/config.go +++ b/pkg/rein.go @@ -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) } @@ -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 @@ -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 @@ -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 @@ -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