Create config dir if using default configPath

This commit is contained in:
mlsmaycon 2021-06-20 23:01:12 +02:00
parent 41b50a08d4
commit 06c7af058b

View File

@ -6,6 +6,7 @@ import (
"github.com/wiretrustee/wiretrustee/connection" "github.com/wiretrustee/wiretrustee/connection"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
) )
// Config Configuration type // Config Configuration type
@ -23,6 +24,15 @@ type Config struct {
//Write writes configPath to a file //Write writes configPath to a file
func (cfg *Config) Write(path string) error { func (cfg *Config) Write(path string) error {
if path == defaultConfigPath {
configDir := filepath.Dir(path)
err := os.MkdirAll(configDir, 0750)
if err != nil {
return err
}
}
bs, err := json.Marshal(cfg) bs, err := json.Marshal(cfg)
if err != nil { if err != nil {
return err return err