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

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

Programatically determine if in production in revel framework

问题

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

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

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

英文:

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

答案1

得分: 5

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

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

例如:

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

There are exported global variables in the revel package:

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

So for example:

  1. if revel.DevMode {
  2. // Running in development mode
  3. } else {
  4. // Production mode
  5. }

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:

确定