package growsync import ( "fmt" "io/ioutil" "os" "path/filepath" "github.com/goccy/go-yaml" ) type growiConfig struct { url string `yaml:"growi_url"` userName string `yaml:"user_name"` token string `yaml:"token"` localRoot string `yaml:"local_root"` } func parseConfig() (*growiConfig, error) { configFilePATH, _ := getConfingPATH() configBytes, err := ioutil.ReadFile(configFilePATH) if err != nil { return nil, err } config := growiConfig{} if err := yaml.Unmarshal(configBytes, &config); err != nil { return nil, err } return &config, nil } func getConfingPATH() (string, error) { home, err := os.UserHomeDir() if err != nil { return "", err } configFilePATH := filepath.Join(home, ".config", "growsync", "config.yaml") if !fileCheck(configFilePATH) { return "", fmt.Errorf("[ERROR] conf file not found") } return configFilePATH, nil } func fileCheck(conf string) bool { info, err := os.Stat(conf) if os.IsNotExist(err) { return false } return !info.IsDir() }