// Init is called to initialize the application. func Init(configKey string) { // Init the configuration system. if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil { fmt.Println("Error initalizing configuration system", err) os.Exit(1) } // Init the log system. logLevel := func() int { ll, err := cfg.Int(cfgLoggingLevel) if err != nil { return log.USER } return ll } log.Init(os.Stderr, logLevel) // Log all the configuration options log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log()) // Load user defined custom headers. HEADERS should be key:value,key:value if hs, err := cfg.String("HEADERS"); err == nil { hdrs := strings.Split(hs, ",") for _, hdr := range hdrs { if kv := strings.Split(hdr, ":"); len(kv) == 2 { log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1]) app.userHeaders[kv[0]] = kv[1] } } } }
func init() { // This is being added to showcase configuration. os.Setenv("KIT_LOGGING_LEVEL", "1") os.Setenv("KIT_MIN_ROUTINES", "1") os.Setenv("KIT_MAX_ROUTINES", "10") // Init the configuration system. if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil { fmt.Println("Error initalizing configuration system", err) os.Exit(1) } // Init the log system. logLevel := func() int { ll, err := cfg.Int(cfgLoggingLevel) if err != nil { return log.USER } return ll } log.Init(os.Stderr, logLevel) // Log all the configuration options log.User("startup", "init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log()) }
// Init is called to initialize the application. func Init(configKey string) { // Init the configuration system. if err := cfg.Init(cfg.EnvProvider{Namespace: configKey}); err != nil { fmt.Println("Error initalizing configuration system", err) os.Exit(1) } // Init the log system. logLevel := func() int { ll, err := cfg.Int(cfgLoggingLevel) if err != nil { return log.USER } return ll } log.Init(os.Stderr, logLevel) // Log all the configuration options log.User("startup", "Init", "\n\nConfig Settings: %s\n%s\n", configKey, cfg.Log()) // Init MongoDB if configured. if _, err := cfg.String(cfgMongoHost); err == nil { app.useMongo = true cfg := mongo.Config{ Host: cfg.MustString(cfgMongoHost), AuthDB: cfg.MustString(cfgMongoAuthDB), DB: cfg.MustString(cfgMongoDB), User: cfg.MustString(cfgMongoUser), Password: cfg.MustString(cfgMongoPassword), } if err := mongo.Init(cfg); err != nil { log.Error("startup", "Init", err, "Initializing MongoDB") os.Exit(1) } } // Load user defined custom headers. HEADERS should be key:value,key:value if hs, err := cfg.String("HEADERS"); err == nil { hdrs := strings.Split(hs, ",") for _, hdr := range hdrs { if kv := strings.Split(hdr, ":"); len(kv) == 2 { log.User("startup", "Init", "User Headers : %s:%s", kv[0], kv[1]) app.userHeaders[kv[0]] = kv[1] } } } }