英文:
Programatically determine if in production in revel framework
问题
在Revel框架中,你可以通过编程方式检测当前是否处于生产模式或开发模式。以下是一种常见的方法:
- 导入Revel框架的相关包:
 
import "github.com/revel/revel"
- 使用
revel.RunMode函数来获取当前的运行模式: 
mode := revel.RunMode
- 判断当前的运行模式:
 
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论