summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile21
-rw-r--r--config.FormatENV.go45
-rw-r--r--config.Load.go146
-rw-r--r--config.Save.go91
-rw-r--r--config.proto21
5 files changed, 1 insertions, 323 deletions
diff --git a/Makefile b/Makefile
index 1013fb0..d9c9404 100644
--- a/Makefile
+++ b/Makefile
@@ -1,25 +1,6 @@
-all: autogenpb goimports vet
+all: goimports vet
@echo This GO code passes the compile checks
-# fixes your numbers if you move things around
-# THIS TOTALLY BREAKS THE POINT OF PROTOBUF
-# To work around that breaking, you must change the version
-# also, all the wrapping code must support this. which it doesn't
-proto-renumber: clean
- autogenpb --renumber --proto config.proto
- make goimports vet
-
-autogenpb:
- autogenpb --proto config.proto
-
-generate: clean
- go mod init
- go mod tidy
- go generate
-
-go-generate:
- rm -f *.pb.go *.patch
-
goimports:
goimports -w *.go
diff --git a/config.FormatENV.go b/config.FormatENV.go
deleted file mode 100644
index 1775ad6..0000000
--- a/config.FormatENV.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package config
-
-/*
-func formatENV() (string, error) {
- if configPB == nil {
- return "", errors.New("configPB not initialized")
- }
-
- var out string
- uniques := make(map[string]*Config) // check to make sure there are no duplicate entries
-
- for c := range configPB.IterAll() {
- key := strings.ToLower(c.Key)
- if len(strings.Fields(key)) != 1 {
- log.Info("dropping invalid key = ", c.Key, "value =", c.Value)
- continue
- }
- found := findByLower(key)
- if found == nil {
- log.Info("findByKey() got nil for key:", key)
- }
- // todo: warn about duplicates?
- uniques[key] = found
- }
-
- for key, c := range uniques {
- if c == nil {
- log.Info("key has nil c", key)
- continue
- }
- line := fmt.Sprintf("%s=%s", c.Key, c.Value)
- out += line + "\n"
- }
- return out, nil
-}
-
-func findByLower(lookingFor string) *Config {
- for c := range configPB.IterAll() {
- if strings.ToLower(c.Key) == strings.ToLower(lookingFor) {
- return c
- }
- }
- return nil
-}
-*/
diff --git a/config.Load.go b/config.Load.go
deleted file mode 100644
index 9f8f6ce..0000000
--- a/config.Load.go
+++ /dev/null
@@ -1,146 +0,0 @@
-package config
-
-import (
- "os"
- "path/filepath"
-
- "go.wit.com/lib/ENV"
-)
-
-// loads your applications config file from
-// ~/.config/<appname>/config.text
-func (pb *Config) Load() error {
- filename, err := getConfigFilenameTEXT()
- if err != nil {
- return err
- }
-
- _, err = SetFilename(pb, filename)
- if err != nil {
- return err
- }
-
- saveMu.Lock()
- defer saveMu.Unlock()
- err = loadTEXT(pb, filename)
- return err
-}
-
-/*
-func loadENV() error {
- if configPB != nil {
- log.Info("configPB already loaded")
- return errors.New("configPB already loaded")
- }
- filename, err := getConfigFilenameENV()
- if err != nil {
- return err
- }
- // log.Info("loadENV()", filename)
- stuff, err := os.ReadFile(filename)
- if err != nil {
- return err
- }
- saveMu.Lock()
- defer saveMu.Unlock()
- configPB = NewConfigs()
- for _, line := range strings.Split(string(stuff), "\n") {
- line = strings.TrimSpace(line)
- if line == "" {
- continue
- }
- parts := strings.Split(line, "=")
- if len(parts) != 2 {
- // log.Info("INVALID LINE:", i, line)
- continue
- }
- c := new(Config)
- c.Key = parts[0]
- c.Value = parts[1]
- configPB.Append(c)
- // log.Printf("ENV LINE: (%v)\n", c)
- }
-
- return err
-}
-
-func getConfigFilenameENV() (string, error) {
- appname, err := GetAppname() // already configured by your application
- if err != nil {
- return "", err
- }
-
- configdir, err := getConfigDir()
- if err != nil {
- return "", err
- }
-
- filename := filepath.Join(configdir, appname+".ENV")
- return filename, nil
-}
-*/
-
-func getConfigFilenameTEXT() (string, error) {
- appname, err := ENV.GetAppname() // already configured by your application
- if err != nil {
- return "", err
- }
-
- configdir, err := getConfigDir()
- if err != nil {
- return "", err
- }
-
- filename := filepath.Join(configdir, appname+".text")
- return filename, nil
-}
-
-/*
-func GetAppname() (string, error) {
- if APPNAME != "" {
- return APPNAME, nil
- }
- return "", errors.New("your application must setup config.Init()")
-}
-
-func GetUsername() string {
- if Get("username") != "" {
- return Get("username")
- }
- usr, _ := user.Current()
- if usr.Username != "" {
- return usr.Username
- }
- return "notsure" // OS Idiocracy
-}
-*/
-
-func getCacheDir() (string, error) {
- // if Get("cacheDir") != "" {
- // return Get("cacheDir"), nil
- // }
-
- cacheDir, _ := os.UserCacheDir()
-
- appname, err := ENV.GetAppname() // application should have already configured this
- if err != nil {
- return cacheDir, err
- }
-
- return filepath.Join(cacheDir, appname), nil
-}
-
-func getConfigDir() (string, error) {
- // if Get("configDir") != "" {
- // return Get("configDir"), nil
- // }
-
- configDir, _ := os.UserConfigDir()
-
- appname, err := ENV.GetAppname() // application should have already configured this
- if err != nil {
- return configDir, err
- }
-
- return filepath.Join(configDir, appname), nil
-}
diff --git a/config.Save.go b/config.Save.go
deleted file mode 100644
index c317e73..0000000
--- a/config.Save.go
+++ /dev/null
@@ -1,91 +0,0 @@
-package config
-
-import (
- "sync"
-)
-
-// an experiment to see if this is useful
-var saveMu sync.RWMutex
-
-/*
-// returns true if config is working okay
-func InitValid() bool {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- // todo: try to re-init it here
- return false
- }
- return true
-}
-
-// saves your applications config file
-func Save() error {
- return saveENV()
-}
-
-func saveENV() error {
- filename, err := getConfigFilenameENV()
- if err != nil {
- return err
- }
- saveMu.Lock()
- defer saveMu.Unlock()
- outENV, err := formatENV()
- if err == nil {
- log.Info("SAVEENV IS RUNNING")
- log.Info("SAVEENV IS RUNNING")
- log.Info("SAVEENV IS RUNNING")
- log.Info(outENV)
- }
- return os.WriteFile(filename, []byte(outENV), 0644)
-}
-
-func Get(flag string) string {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- return ""
- }
- c := findByLower(flag)
- if c == nil {
- return ""
- }
-
- return c.Value
-}
-
-func True(flag string) bool {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- return false
- }
- found := configPB.findByKey(flag)
- if found == nil {
- return false
- }
- if strings.ToLower(found.Value) == "true" {
- return true
- }
- return false
-}
-
-func Set(key string, newValue string) error {
- saveMu.Lock()
- defer saveMu.Unlock()
- if configPB == nil {
- return NotInitialized
- }
- found := configPB.findByKey(key)
- if found != nil {
- found.Value = newValue
- }
-
- newvar := new(Config)
- newvar.Key = key
- newvar.Value = newValue
- configPB.Append(newvar)
- return nil
-}
-*/
diff --git a/config.proto b/config.proto
deleted file mode 100644
index 19e8481..0000000
--- a/config.proto
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
-
-syntax = "proto3";
-
-package config;
-
-import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
-
-message Config { //
- string key = 1; // config key name `autogenpb:unique` `autogenpb:sort`
- string value = 2; // config value name
- bool global = 3; // was defined in application OS settings
- string help = 4; // text for explaining the ENV key/value
-}
-
-message Configs { // `autogenpb:marshal` `autogenpb:nomutex`
- string uuid = 1; // `autogenpb:uuid:3135d0f9-82a9-40b6-8aa1-b683ebe7bedd`
- string version = 2; // `autogenpb:version:v0.0.2 go.wit.com/lib/config`
- repeated Config configs = 3;
- string filename = 4; // can store where the filename is so that saves can be automated
-}