aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/main.go b/main.go
index 2c4c2c4..8c49ce3 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "errors"
"fmt"
"os"
)
@@ -11,16 +12,9 @@ type Conf struct {
}
func main() {
- conf := &Conf{
- Source: os.Getenv("CONF_SOURCE"),
- Dest: os.Getenv("CONF_DEST"),
- }
- if err := checkdir(conf.Source); err != nil {
- fmt.Printf("could not find $CONF_SOURCE: %v\n", err)
- os.Exit(1)
- }
- if err := checkdir(conf.Dest); err != nil {
- fmt.Printf("could not find $CONF_DEST: %v\n", err)
+ conf, err := loadConf()
+ if err != nil {
+ fmt.Printf("could not load configuration: %v\n", err)
os.Exit(1)
}
if len(os.Args) < 2 {
@@ -44,13 +38,18 @@ func main() {
}
}
-func checkdir(path string) error {
- info, err := os.Stat(path)
+func loadConf() (*Conf, error) {
+ source := os.Getenv("CONF_SOURCE")
+ info, err := os.Stat(source)
if err != nil {
- return err
+ return nil, err
}
if !info.IsDir() {
- return fmt.Errorf("%s is not a directory", path)
+ return nil, errors.New("CONF_SOURCE is not a directory")
+ }
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, err
}
- return nil
+ return &Conf{Source: source, Dest: home}, nil
}