4c1e56ccce
* correct config issues #271 #272 * rename type tags * replace env lib * move to config module * read flags * show e2e logs on error * extract env * replace deprecated env var * increment index * check replica numbers do not start with 0 * remove test suite * error handling * refactor flags * flags test * file test * file test * config tests * extend tests * test mixed mode * simplify * simplify * test mask * correct uniqe replicas * Update types_test.go * e2e test with file mode
35 lines
629 B
Go
35 lines
629 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"), nil
|
|
}
|
|
return configFile, nil
|
|
}
|