在Revel框架中,通过编程方式确定是否处于生产环境。

huangapple go评论64阅读模式
英文:

Programatically determine if in production in revel framework

问题

在Revel框架中,你可以通过编程方式检测当前是否处于生产模式或开发模式。以下是一种常见的方法:

  1. 导入Revel框架的相关包:
import "github.com/revel/revel"
  1. 使用revel.RunMode函数来获取当前的运行模式:
mode := revel.RunMode
  1. 判断当前的运行模式:
if mode == "dev" {
    // 开发模式下的逻辑
} else if mode == "prod" {
    // 生产模式下的逻辑
} else {
    // 其他模式下的逻辑
}

通过以上步骤,你可以根据当前的运行模式执行相应的逻辑。请注意,具体的运行模式名称可能会根据你的配置而有所不同,你可以根据实际情况进行调整。

英文:

How can I programatically detect if I'm in production mode or development mode in revel framework?

答案1

得分: 5

revel 包中有一些导出的全局变量:

var (
    RunMode string // 应用程序定义的(默认为“dev”或“prod”)
    DevMode bool   // 如果为 true,则表示运行在开发模式下
)

例如:

if revel.DevMode {
    // 运行在开发模式下
} else {
    // 生产模式
}
英文:

There are exported global variables in the revel package:

var (
    RunMode string // Application-defined (by default, "dev" or "prod")
    DevMode bool   // if true, RunMode is a development mode.
)

So for example:

if revel.DevMode {
    // Running in development mode
} else {
    // Production mode
}

huangapple
  • 本文由 发表于 2015年7月7日 17:27:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/31264754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定