New standard GO project layout
[ric-plt/appmgr.git] / cmd / appmgr / config.go
similarity index 56%
rename from src/config.go
rename to cmd/appmgr/config.go
index e9ede6b..5e1975e 100755 (executable)
 package main
 
 import (
-    "flag"
-    "log"
-    "github.com/spf13/viper"
-    "github.com/fsnotify/fsnotify"
+       "flag"
+       "github.com/fsnotify/fsnotify"
+       "github.com/spf13/viper"
+       "log"
 )
 
-const DEFAULT_CONFIG_FILE = "../config/appmgr.yaml"
+const DEFAULT_CONFIG_FILE = "config/appmgr.yaml"
 
 func parseCmd() string {
-    var fileName *string
-    fileName = flag.String("f", DEFAULT_CONFIG_FILE, "Specify the configuration file.")
-    flag.Parse()
+       var fileName *string
+       fileName = flag.String("f", DEFAULT_CONFIG_FILE, "Specify the configuration file.")
+       flag.Parse()
 
-    return *fileName
+       return *fileName
 }
 
 func loadConfig() {
-    viper.SetConfigFile(parseCmd())
+       viper.SetConfigFile(parseCmd())
 
-    if err := viper.ReadInConfig(); err != nil {
-        log.Fatalf("Error reading config file, %s", err)
-    }
-    log.Printf("Using config file: %s\n", viper.ConfigFileUsed())
+       if err := viper.ReadInConfig(); err != nil {
+               log.Fatalf("Error reading config file, %s", err)
+       }
+       log.Printf("Using config file: %s\n", viper.ConfigFileUsed())
 
-    // Watch for config file changes and re-read data ...
-    watch()
+       // Watch for config file changes and re-read data ...
+       watch()
 }
 
 func watch() {
-    viper.WatchConfig()
-    viper.OnConfigChange(func(e fsnotify.Event) {
-        log.Println("config file changed ", e.Name)
-    })
+       viper.WatchConfig()
+       viper.OnConfigChange(func(e fsnotify.Event) {
+               log.Println("config file changed ", e.Name)
+       })
 }