2023-10-28 14:42:29 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2023-11-03 01:01:33 -04:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2023-10-28 14:42:29 -04:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type config struct {
|
2023-11-03 01:01:33 -04:00
|
|
|
Mongo *MongoConfig `mapstructure:"mongo"`
|
|
|
|
YoutubeConfig *YoutubeConfig `mapstructure:"youtube"`
|
|
|
|
PcoConfig *PcoConfig `mapstructure:"pco"`
|
|
|
|
JwtSecret string `mapstructure:"jwt_secret"`
|
|
|
|
Env string `mapstructure:"env"`
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type MongoConfig struct {
|
2023-10-28 17:50:44 -04:00
|
|
|
Uri string `mapstructure:"uri"`
|
|
|
|
EntDb string `mapstructure:"ent_db"`
|
|
|
|
EntCol string `mapstructure:"ent_col"`
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-03 01:01:33 -04:00
|
|
|
type YoutubeConfig struct {
|
|
|
|
ClientId string `mapstructure:"client_id"`
|
|
|
|
ClientSecret string `mapstructure:"client_secret"`
|
|
|
|
Scopes []string `mapstructure:"scopes"`
|
|
|
|
AuthUri string `mapstructure:"auth_uri"`
|
|
|
|
TokenUri string `mapstructure:"token_uri"`
|
|
|
|
scope string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (yt *YoutubeConfig) Scope() string {
|
|
|
|
if yt.scope == "" {
|
|
|
|
for i, str := range yt.Scopes {
|
|
|
|
yt.Scopes[i] = fmt.Sprintf("https://www.googleapis.com%s", str)
|
|
|
|
}
|
|
|
|
yt.scope = strings.Join(yt.Scopes, " ")
|
|
|
|
}
|
|
|
|
return yt.scope
|
|
|
|
}
|
|
|
|
|
|
|
|
type PcoConfig struct {
|
|
|
|
ClientId string `mapstructure:"client_id"`
|
|
|
|
ClientSecret string `mapstructure:"client_secret"`
|
|
|
|
AuthUri string `mapstructure:"auth_uri"`
|
|
|
|
TokenUri string `mapstructure:"token_uri"`
|
|
|
|
}
|
|
|
|
|
2023-10-28 14:42:29 -04:00
|
|
|
var cfg *config
|
|
|
|
|
2023-10-28 17:50:44 -04:00
|
|
|
func Init() {
|
2023-11-01 22:40:50 -04:00
|
|
|
viper.SetConfigName("config") // name of config file (without extension)
|
|
|
|
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
|
2023-10-28 17:50:44 -04:00
|
|
|
viper.AddConfigPath("/etc/capstone") // path to look for the config file in
|
2023-10-28 14:42:29 -04:00
|
|
|
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg = &config{}
|
|
|
|
|
|
|
|
err = viper.Unmarshal(cfg)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Config() *config {
|
|
|
|
return cfg
|
|
|
|
}
|