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:
19
config/path.go
Normal file
19
config/path.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user