adguardhome-sync/pkg/config/file.go
Areg Vrtanesyan 5a3f2004bc
Update file.go to load from default .adguardhome-sync.yaml file (#313)
* Updateing file.go to load from default .adguardhome-sync.yaml file

* Update file_test.go to load from default .adguardhome-sync.yaml file
2024-03-12 18:41:12 +01:00

34 lines
634 B
Go

package config
import (
"os"
"path/filepath"
"github.com/bakito/adguardhome-sync/pkg/types"
"gopkg.in/yaml.v3"
)
func readFile(cfg *types.Config, path string) error {
if _, err := os.Stat(path); err == nil {
b, err := os.ReadFile(path)
if err != nil {
return err
}
if err := yaml.Unmarshal(b, cfg); err != nil {
return err
}
}
return nil
}
func configFilePath(configFile string) (string, error) {
if configFile == "" {
// Find home directory.
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".adguardhome-sync.yaml"), nil
}
return configFile, nil
}