package config

import "github.com/beego/beego/v2/server/web"

type RedisConfig struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Password string `json:"password"`
	DB       int    `json:"db"`
}

type Secret struct {
	Key string `json:"key"`
	IV  string `json:"iv"`
}

func GetGatewayHost() string {
	host, _ := web.AppConfig.String("gateway::host")
	return host
}

func GetPortalHost() string {
	host, _ := web.AppConfig.String("portal::host")
	return host
}

func GetRedisConfig() (*RedisConfig, error) {
	// 获取redis配置
	redisConfig := &RedisConfig{}
	err := web.AppConfig.Unmarshaler("redis", redisConfig)
	// 使用redisConfig...}
	return redisConfig, err
}

func GetSecret() *Secret {
	// 获取secret配置
	secret := &Secret{
		Key: web.AppConfig.DefaultString("secret::key", "thisis32bitlongpassphraseimusing"),
		IV:  web.AppConfig.DefaultString("secret::iv", "1234567890123456"),
	}
	// 使用secret...
	return secret
}
