Create the configuration and log file in configuration directory
This commit is contained in:
parent
d0027b0add
commit
2a1c583b2b
2 changed files with 16 additions and 3 deletions
|
|
@ -82,8 +82,15 @@ func New() *Config {
|
|||
|
||||
func (cfg *Config) Load() error {
|
||||
path, _ := os.UserConfigDir()
|
||||
path = filepath.Join(path, Name+".yml")
|
||||
// Open the existing configuration file with read-only flag.
|
||||
// Create the configuration directory if it does not exist already.
|
||||
path = filepath.Join(path, Name)
|
||||
err := os.MkdirAll(path, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path = filepath.Join(path, "config.yml")
|
||||
// Open the configuration file with create and read-write flag.
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
8
main.go
8
main.go
|
|
@ -17,7 +17,13 @@ func init() {
|
|||
flag.StringVar(&tokenFlag, "token", "", "The authentication token.")
|
||||
|
||||
path, _ := os.UserCacheDir()
|
||||
path = filepath.Join(path, config.Name+".log")
|
||||
path = filepath.Join(path, config.Name)
|
||||
err := os.MkdirAll(path, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
path = filepath.Join(path, "logs.txt")
|
||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue