代码拉取完成,页面将自动刷新
package env
import (
"os"
"path/filepath"
"gitee.com/neuro-netw0rk/server-golib/utils"
"github.com/gin-gonic/gin"
)
const DefaultRootPath = "."
const LogLevel = "LOG_LEVEL"
const (
NNClusterType = "NN_CLUSTER_TYPE"
DockAppName = "APP_NAME"
DockerRunEnv = "RUN_ENV"
)
// RUN_ENV: (prod,tips,test)
const (
RunEnvDEV = 0
RunEnvQAT = 1
RunEnvPRE = 2
RunEnvPRD = 3
RunEnvDOC = 4
)
var (
LocalIP string
AppName string
RunMode string
ServerID string
runEnv int
rootPath string
dockerPlateForm bool
logLevel string
)
func init() {
LocalIP = utils.GetLocalIp()
dockerPlateForm = false
if r := os.Getenv(NNClusterType); r != "" {
dockerPlateForm = true
// 容器里,appName在编排的时候决定
if n := os.Getenv(DockAppName); n != "" {
AppName = n
println("docker env, APP_NAME=", n)
} else {
println("docker env, lack APP_NAME!!!")
}
}
// 运行环境
RunMode = gin.ReleaseMode
r := os.Getenv(DockerRunEnv)
switch r {
case "doc":
runEnv = RunEnvDOC
case "prd":
runEnv = RunEnvPRD
case "pre":
runEnv = RunEnvPRE
RunMode = gin.DebugMode
case "qat":
runEnv = RunEnvQAT
RunMode = gin.DebugMode
case "dev":
runEnv = RunEnvDEV
RunMode = gin.DebugMode
default:
runEnv = RunEnvDEV
RunMode = gin.DebugMode
}
gin.SetMode(RunMode)
initDBSecret()
logLevel = os.Getenv(LogLevel)
}
func IsDockerPlatform() bool {
return dockerPlateForm
}
func SetAppName(appName string) {
if !dockerPlateForm {
AppName = appName
}
}
func GetAppName() string {
return AppName
}
// SetRootPath 设置应用的根目录
func SetRootPath(r string) {
if !dockerPlateForm {
rootPath = r
}
}
func GetRootPath() string {
if rootPath != "" {
return rootPath
} else {
return DefaultRootPath
}
}
// GetConfDirPath 返回配置文件目录绝对地址
func GetConfDirPath() string {
return filepath.Join(GetRootPath(), "conf")
}
func GetLogDirPath() string {
return filepath.Join(GetRootPath(), "log")
}
func GetRunEnv() int {
return runEnv
}
func SetServerID(serverID string) {
ServerID = serverID
}
func GetServerID() string {
return ServerID
}
func GetLogLevel() string {
return logLevel
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。