douxia2137 2014-01-26 07:36
浏览 66
已采纳

在revel.Controller中,如何在app.conf中设置端口

Using revel framework (golang), how can I get port I set in app.conf?

// in app.conf
http.port=9090

And I have to use my server's port number in controllers (for example OAuth coding) such as

requestToken, url, err := TWITTER.GetRequestTokenAndUrl(
    "http://127.0.0.1:9090/Application/Authenticate",
)

I don't want to write port number by hard coding. Using revel, is there any good way to get port number (or any other conf values) set in app.conf?

Thank you in advance

  • 写回答

2条回答 默认 最新

  • dongtang5057 2014-01-26 08:00
    关注

    May be this documentation will be useful - http://robfig.github.io/revel/docs/godoc/config.html

    For example

    // Load app.conf
    var err error
    Config, err = LoadConfig("app.conf")
    if err != nil || Config == nil {
        log.Fatalln("Failed to load app.conf:", err)
    }
    HttpPort = Config.IntDefault("http.port", 9000)
    

    An another approach may be used instead direct loading (see modules/db/app/db.go)

    import (
        "github.com/robfig/revel"
    )
    
    if option, found = revel.Config.String("option"); !found {
        revel.ERROR.Fatal("No option found.")
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码