log.Println("OS DBTYPE:", dbType)
log.Println("Get Env from os.env")
log.Println("Init viper")
func getConfig(projectName string) {
viper.SetConfigName("config") // name of config file (without extension)
viper.AddConfigPath(".") // optionally look for config in the working directory
viper.AddConfigPath(fmt.Sprintf("$HOME/.%s", projectName)) // call multiple times to add many search paths
viper.AddConfigPath(fmt.Sprintf("/data/docker/config/%s", projectName)) // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s", err))
// GetMysqlConnectingString func
func GetMysqlConnectingString() string {
usr := viper.GetString("mysql.user")
pwd := viper.GetString("mysql.password")
host := viper.GetString("mysql.host")
db := viper.GetString("mysql.db")
charset := viper.GetString("mysql.charset")
return fmt.Sprintf("%s:%[email protected](%s:3306)/%s?charset=%s&parseTime=true&loc=Local", usr, pwd, host, db, charset) // GetHerokuConnectingString func
func GetHerokuConnectingString() string {
return os.Getenv("DATABASE_URL")
func GetSMTPConfig() (server string, port int, user, pwd string) {
server = os.Getenv("MAIL_SMTP")
port, _ = strconv.Atoi(os.Getenv("MAIL_SMTP_PORT"))
user = os.Getenv("MAIL_USER")
pwd = os.Getenv("MAIL_PASSWORD")
server = viper.GetString("mail.smtp")
port = viper.GetInt("mail.smtp-port")
user = viper.GetString("mail.user")
pwd = viper.GetString("mail.password")
func GetServerURL() (url string) {
url = os.Getenv("SERVER_URL")
url = viper.GetString("server.url")
func GetDBType() string {
dbtype := os.Getenv("DBTYPE")
return GetDBType() == "heroku"