diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 00:15:41 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 00:15:41 -0500 |
| commit | fc17dc394aedbc5fd636676202bad40c1f98c1de (patch) | |
| tree | 197ff50da15f186c38d50a71fede7b0c160ee57f /load.go | |
| parent | 3b4821a3af62376d675699493e01cd07891ad69c (diff) | |
implement application specific Config files (and Verbose())
Diffstat (limited to 'load.go')
| -rw-r--r-- | load.go | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -31,12 +31,12 @@ var ErrMarshal error = fmt.Errorf("protobuf parse error") func ConfigLoad(pb proto.Message, argname string, protoname string) error { var fullname string var err error - homeDir, err := os.UserHomeDir() + configDir, err := os.UserConfigDir() if err != nil { return err } - fullname = filepath.Join(homeDir, ".config", argname, protoname+".text") + fullname = filepath.Join(configDir, argname, protoname+".text") SetFilename(pb, fullname) // if both don't exist or both are empty, return known errors @@ -72,11 +72,11 @@ func LoadCache(pb proto.Message, argname string, protoname string) error { os.MkdirAll(fullpath, os.ModePerm) fullname := filepath.Join(fullpath, protoname+".pb") _, err := SetFilename(pb, fullname) - return errors.Join(err, Load(pb)) + return errors.Join(err, LoadPB(pb)) } // this logic isn't great yet -func Load(pb proto.Message) error { +func LoadPB(pb proto.Message) error { fullname, err := GetFilename(pb) if err != nil { return err @@ -125,6 +125,10 @@ func Load(pb proto.Message) error { return nil } +func LoadFromFilename(pb proto.Message, fullname string) error { + return LoadFile(pb, fullname) +} + func LoadFile(pb proto.Message, fullname string) error { if strings.HasSuffix(fullname, ".text") { return loadTEXT(pb, fullname) @@ -153,17 +157,17 @@ func loadPB(pb proto.Message, fullname string) error { return nil } -func LoadPB(pb proto.Message, argname string, protoname string) (string, error) { +func LoadConfigPB(pb proto.Message, argname string, protoname string) (string, error) { var fullname string if strings.HasPrefix(argname, "/") { fullname = filepath.Join(argname, protoname+".pb") } else { - homeDir, err := os.UserHomeDir() + configDir, err := os.UserConfigDir() if err != nil { return "", err } - fullname = filepath.Join(homeDir, ".config", argname, protoname+".pb") + fullname = filepath.Join(configDir, argname, protoname+".pb") } data, err := loadFile(fullname) |
