57 lines
951 B
Go
57 lines
951 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
Version string
|
|
Release []ConfigType
|
|
}
|
|
|
|
type ConfigType struct {
|
|
ReleaseType string
|
|
Data struct {
|
|
API_PORT int
|
|
DB_HOST string
|
|
DB_DRIVER string
|
|
DB_USER string
|
|
DB_PASSWORD string
|
|
DB_NAME string
|
|
DB_PORT int
|
|
}
|
|
}
|
|
|
|
var Conf = &Config{}
|
|
|
|
var Configurations ConfigType
|
|
|
|
func LoadConfigurations(release string) bool {
|
|
// Read config file
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("json")
|
|
viper.AddConfigPath(".")
|
|
|
|
// Get all configurations from config file
|
|
if err := viper.ReadInConfig(); err == nil {
|
|
err = viper.Unmarshal(Conf)
|
|
if err != nil {
|
|
log.Printf("Unable to decode into config struct: %v", err)
|
|
}
|
|
} else {
|
|
fmt.Printf("ERROR READING CONFIG FILE: %v\n", err)
|
|
}
|
|
|
|
for _, v := range Conf.Release {
|
|
if v.ReleaseType == release {
|
|
Configurations = v
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|