config: add default path, customized configs.

A customised config is an ini file with a [default] section and some
other name sections; a config file is loaded from the default section
with any keys in the named section being added in, overriding keys in
the host. This allows for, e.g. setting different paths based on the
host name or operating system.
This commit is contained in:
2022-02-20 17:40:38 -08:00
parent c7c51568d8
commit b893e99864
6 changed files with 465 additions and 0 deletions

19
config/path.go Normal file
View File

@@ -0,0 +1,19 @@
//go:build ignore
// +build ignore
package config
import (
"os/user"
"path/filepath"
)
// DefaultConfigPath returns a sensible default configuration file path.
func DefaultConfigPath(dir, base string) string {
user, err := user.Current()
if err != nil || user.HomeDir == "" {
return filepath.Join(dir, base)
}
return filepath.Join(user.HomeDir, dir, base)
}