78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"gitea.com/bitwsd/core/common/log"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
Log log.LogConfig `mapstructure:"log"`
|
|
Server ServerConfig `mapstructure:"server"`
|
|
Database DatabaseConfig `mapstructure:"database"`
|
|
Redis RedisConfig `mapstructure:"redis"`
|
|
UploadDir string `mapstructure:"upload_dir"`
|
|
Limit LimitConfig `mapstructure:"limit"`
|
|
Aliyun AliyunConfig `mapstructure:"aliyun"`
|
|
}
|
|
|
|
type LimitConfig struct {
|
|
FormulaRecognition int `mapstructure:"formula_recognition"`
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
Port int `mapstructure:"port"`
|
|
Mode string `mapstructure:"mode"`
|
|
}
|
|
|
|
func (c *ServerConfig) IsDebug() bool {
|
|
return c.Mode == "debug"
|
|
}
|
|
|
|
type RedisConfig struct {
|
|
Addr string `mapstructure:"addr"`
|
|
Password string `mapstructure:"password"`
|
|
DB int `mapstructure:"db"`
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Driver string `mapstructure:"driver"`
|
|
Host string `mapstructure:"host"`
|
|
Port int `mapstructure:"port"`
|
|
Username string `mapstructure:"username"`
|
|
Password string `mapstructure:"password"`
|
|
DBName string `mapstructure:"dbname"`
|
|
MaxIdle int `mapstructure:"max_idle"`
|
|
MaxOpen int `mapstructure:"max_open"`
|
|
}
|
|
|
|
type OSSConfig struct {
|
|
Endpoint string `mapstructure:"endpoint"` // 外网endpoint
|
|
InnerEndpoint string `mapstructure:"inner_endpoint"` // 内网endpoint
|
|
AccessKeyID string `mapstructure:"access_key_id"`
|
|
AccessKeySecret string `mapstructure:"access_key_secret"`
|
|
BucketName string `mapstructure:"bucket_name"`
|
|
}
|
|
|
|
type SmsConfig struct {
|
|
AccessKeyID string `mapstructure:"access_key_id"`
|
|
AccessKeySecret string `mapstructure:"access_key_secret"`
|
|
SignName string `mapstructure:"sign_name"`
|
|
TemplateCode string `mapstructure:"template_code"`
|
|
}
|
|
|
|
type AliyunConfig struct {
|
|
Sms SmsConfig `mapstructure:"sms"`
|
|
OSS OSSConfig `mapstructure:"oss"`
|
|
}
|
|
|
|
var GlobalConfig Config
|
|
|
|
func Init(configPath string) error {
|
|
viper.SetConfigFile(configPath)
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return viper.Unmarshal(&GlobalConfig)
|
|
}
|