youtu_ecpm/pkg/config/viper.go

48 lines
998 B
Go

package config
import (
"github.com/spf13/viper"
)
const (
LogLevelKey = "LOG_LEVEL" // 日志级别
LogPathKey = "LOG_PATH" // 日志路径
LogFormatKey = "LOG_FORMAT" // 日志格式
PortKey = "PORT" // 端口
AppEnvKey = "APP_ENV" // 环境
)
func init() {
viper.SetDefault(LogLevelKey, "debug")
viper.SetDefault(LogPathKey, "./data/logs/ecpm.log")
viper.SetDefault(LogFormatKey, "json")
viper.SetDefault(PortKey, "8080")
viper.SetDefault(AppEnvKey, "")
viper.AutomaticEnv()
}
// GetLogLevel 获取日志级别
func GetLogLevel() string {
return viper.GetString(LogLevelKey)
}
// GetLogPath 获取日志路径
func GetLogPath() string {
return viper.GetString(LogPathKey)
}
// GetLogFormat 获取日志格式
func GetLogFormat() string {
return viper.GetString(LogFormatKey)
}
// GetPort 获取端口
func GetPort() string {
return viper.GetString(PortKey)
}
// GetAppEnv 获取环境
func GetAppEnv() string {
return viper.GetString(AppEnvKey)
}