codefordenver / shift-api

1 stars 0 forks source link

move database credential to config file #22

Open ShiftRL opened 5 years ago

dviramontes commented 5 years ago

example config package

package config

import (
    "..."
    "github.com/spf13/viper"
)

// Read attempts to read a config file from path.
// The defaults provided will be used if no config file doesn't exist
func Read(name string, defaults map[string]interface{}) *viper.Viper {
    v := viper.New()

    v.SetConfigFile(name)
    v.AddConfigPath(".")
    v.AutomaticEnv()

    for key, val := range defaults {
        v.SetDefault(key, val)
    }

    err := v.ReadInConfig()
    if err != nil {
        log.Info("Internal", "config", "proceeding with defaults and env vars")
    }

    return v
}
dviramontes commented 5 years ago

suggested path pkg/config/config.go