summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.FormatENV.go10
-rw-r--r--config.Load.go27
-rw-r--r--config.Panic.go37
-rw-r--r--config.Save.go16
-rw-r--r--init.go32
-rw-r--r--loadCache.go3
-rw-r--r--loadConfig.go5
-rw-r--r--panic.go15
-rw-r--r--verbose.go55
9 files changed, 40 insertions, 160 deletions
diff --git a/config.FormatENV.go b/config.FormatENV.go
index bd3a156..1775ad6 100644
--- a/config.FormatENV.go
+++ b/config.FormatENV.go
@@ -1,13 +1,6 @@
package config
-import (
- "errors"
- "fmt"
- "strings"
-
- "go.wit.com/log"
-)
-
+/*
func formatENV() (string, error) {
if configPB == nil {
return "", errors.New("configPB not initialized")
@@ -49,3 +42,4 @@ func findByLower(lookingFor string) *Config {
}
return nil
}
+*/
diff --git a/config.Load.go b/config.Load.go
index 6a5f3e9..9f8f6ce 100644
--- a/config.Load.go
+++ b/config.Load.go
@@ -1,13 +1,10 @@
package config
import (
- "errors"
"os"
- "os/user"
"path/filepath"
- "strings"
- "go.wit.com/log"
+ "go.wit.com/lib/ENV"
)
// loads your applications config file from
@@ -29,6 +26,7 @@ func (pb *Config) Load() error {
return err
}
+/*
func loadENV() error {
if configPB != nil {
log.Info("configPB already loaded")
@@ -80,9 +78,10 @@ func getConfigFilenameENV() (string, error) {
filename := filepath.Join(configdir, appname+".ENV")
return filename, nil
}
+*/
func getConfigFilenameTEXT() (string, error) {
- appname, err := GetAppname() // already configured by your application
+ appname, err := ENV.GetAppname() // already configured by your application
if err != nil {
return "", err
}
@@ -96,6 +95,7 @@ func getConfigFilenameTEXT() (string, error) {
return filename, nil
}
+/*
func GetAppname() (string, error) {
if APPNAME != "" {
return APPNAME, nil
@@ -113,15 +113,16 @@ func GetUsername() string {
}
return "notsure" // OS Idiocracy
}
+*/
func getCacheDir() (string, error) {
- if Get("cacheDir") != "" {
- return Get("cacheDir"), nil
- }
+ // if Get("cacheDir") != "" {
+ // return Get("cacheDir"), nil
+ // }
cacheDir, _ := os.UserCacheDir()
- appname, err := GetAppname() // application should have already configured this
+ appname, err := ENV.GetAppname() // application should have already configured this
if err != nil {
return cacheDir, err
}
@@ -130,13 +131,13 @@ func getCacheDir() (string, error) {
}
func getConfigDir() (string, error) {
- if Get("configDir") != "" {
- return Get("configDir"), nil
- }
+ // if Get("configDir") != "" {
+ // return Get("configDir"), nil
+ // }
configDir, _ := os.UserConfigDir()
- appname, err := GetAppname() // application should have already configured this
+ appname, err := ENV.GetAppname() // application should have already configured this
if err != nil {
return configDir, err
}
diff --git a/config.Panic.go b/config.Panic.go
deleted file mode 100644
index 3e2e246..0000000
--- a/config.Panic.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package config
-
-import "google.golang.org/protobuf/proto"
-
-func GetPanic(flag string) string {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- configPanic(flag)
- }
- found := configPB.findByKey(flag)
- if found == nil {
- configPanic(flag)
- }
- return found.Value
-}
-
-func configPanic(varname string) {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- panic("config file is nil")
- }
- panic("config name '" + varname + "' not found")
-}
-
-// should this be a function?
-func LoadPanicPB(pb proto.Message) error {
- fullname, err := GetFilename(pb)
- if err != nil {
- panic("config.LoadPB() err")
- }
- if fullname == "" {
- panic("config.LoadPB() got blank filename = ''")
- }
- return LoadPB(pb)
-}
diff --git a/config.Save.go b/config.Save.go
index 28d5b4b..c317e73 100644
--- a/config.Save.go
+++ b/config.Save.go
@@ -1,16 +1,13 @@
package config
import (
- "os"
- "strings"
"sync"
-
- "go.wit.com/log"
)
// an experiment to see if this is useful
var saveMu sync.RWMutex
+/*
// returns true if config is working okay
func InitValid() bool {
saveMu.Lock()
@@ -24,16 +21,6 @@ func InitValid() bool {
// saves your applications config file
func Save() error {
- /*
- basedir, _ := filepath.Split(configPB.Filename)
- if err := os.MkdirAll(basedir, os.ModePerm); err != nil {
- return err
- }
- saveENV()
- saveMu.Lock()
- defer saveMu.Unlock()
- err := SavePB(configPB)
- */
return saveENV()
}
@@ -101,3 +88,4 @@ func Set(key string, newValue string) error {
configPB.Append(newvar)
return nil
}
+*/
diff --git a/init.go b/init.go
index 5069803..e9c5779 100644
--- a/init.go
+++ b/init.go
@@ -3,12 +3,7 @@ package config
// this is an experiment at this point to
// see how this turns out
-import (
- "fmt"
- "os"
- "path/filepath"
-)
-
+/*
var configPB *Configs
// these are normally what are sent from ldflags
@@ -25,30 +20,6 @@ func Init(appname, version, buildtime string, fromargv []string) error {
argv = fromargv
return loadENV()
- /*
- configDir, err := os.UserConfigDir()
- if err != nil {
- fmt.Println("OS isn't returning UserConfigDir()", err)
- return err
- }
- fullname := filepath.Join(configDir, appname, "config.text")
- configPB = NewConfigs()
- err = loadTEXT(configPB, fullname)
- if err == nil {
- return nil
- }
-
- if errors.Is(err, os.ErrNotExist) {
- // file doesn't exist, make a new file
- return makeNewConfigFile(appname)
- }
- if errors.Is(err, ErrEmpty) {
- fmt.Printf("config file size was empty. out of diskspace? %s\n", fullname)
- return err
- }
- fmt.Println("config.Init()", err)
- return err
- */
}
func makeNewConfigFile(appname string) error {
@@ -71,3 +42,4 @@ func makeNewConfigFile(appname string) error {
err = Save()
return err
}
+*/
diff --git a/loadCache.go b/loadCache.go
index f7ab6ae..40746a3 100644
--- a/loadCache.go
+++ b/loadCache.go
@@ -3,13 +3,14 @@ package config
import (
"errors"
+ "go.wit.com/lib/ENV"
"go.wit.com/log"
"google.golang.org/protobuf/proto"
)
// loads foo.proto from ~/.cache/<appname>/foo.text
func CacheLoad(pb proto.Message) error {
- appname, err := GetAppname() // already configured by your application
+ appname, err := ENV.GetAppname() // already configured by your application
if err != nil {
return err
}
diff --git a/loadConfig.go b/loadConfig.go
index 439e65c..7aec6a4 100644
--- a/loadConfig.go
+++ b/loadConfig.go
@@ -4,13 +4,14 @@ import (
"errors"
"strings"
+ "go.wit.com/lib/ENV"
"go.wit.com/log"
"google.golang.org/protobuf/proto"
)
// loads foo.proto from ~/.config/<appname>/foo.text
func ConfigLoad(pb proto.Message) error {
- appname, err := GetAppname() // already configured by your application
+ appname, err := ENV.GetAppname() // already configured by your application
if err != nil {
return err
}
@@ -63,7 +64,7 @@ func ConfigLoadByName(pb proto.Message, customName string) (string, error) {
if customName == "" {
return "", errors.New("config.Load() customName can not be blank")
}
- appname, err := GetAppname() // already configured by your application
+ appname, err := ENV.GetAppname() // already configured by your application
if err != nil {
return "", err
}
diff --git a/panic.go b/panic.go
new file mode 100644
index 0000000..8ed4df7
--- /dev/null
+++ b/panic.go
@@ -0,0 +1,15 @@
+package config
+
+import "google.golang.org/protobuf/proto"
+
+// should this be a function?
+func LoadPanicPB(pb proto.Message) error {
+ fullname, err := GetFilename(pb)
+ if err != nil {
+ panic("config.LoadPB() err")
+ }
+ if fullname == "" {
+ panic("config.LoadPB() got blank filename = ''")
+ }
+ return LoadPB(pb)
+}
diff --git a/verbose.go b/verbose.go
deleted file mode 100644
index 438475a..0000000
--- a/verbose.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package config
-
-// this is an experiment at this point to
-// see how this turns out
-
-func Verbose() bool {
- // always use the config file value first
- if configPB != nil {
- found := configPB.findByKey("Verbose")
- if found == nil {
- // Verbose isn't in the config. do nothing here
- } else {
- // return what the config file has
- // fmt.Println("returning from the config:" + found.Value)
- if found.Value == "true" {
- return true
- }
- return false
- }
- }
-
- // nothing in the config file. check argv
- for _, v := range argv {
- if v == "--verbose" {
- return true
- }
- }
- return false
-}
-
-func If(key string) bool {
- // always use the config file value first
- if configPB != nil {
- found := configPB.findByKey(key)
- if found == nil {
- // Verbose isn't in the config. do nothing here
- } else {
- // return what the config file has
- // fmt.Println("returning from the config:" + found.Value)
- if found.Value == "true" {
- return true
- }
- return false
- }
- }
-
- // nothing in the config file. check argv
- // todo: turn key to lowercase and check here
- for _, v := range argv {
- if v == "--verbose" {
- return true
- }
- }
- return false
-}