dongliuliu0385 2014-10-27 04:32
浏览 49
已采纳

没有路由器Gorilla Mux的Google Cloud Go处理程序?

https://cloud.google.com/appengine/docs/go/users/

I see here that they do not specify to use any router...: https://cloud.google.com/appengine/docs/go/config/appconfig

In Google Cloud when used with Golang, it says to specify every handler in app.yaml. Does this mean we are not supposed to use 3rd party router for better performance? I would like to Gorilla Mux for router... How would it work if I use other routers for Google App Engine Golang App?

Please let me know. Thanks!

  • 写回答

1条回答 默认 最新

  • dongre6073 2014-10-27 05:24
    关注

    You can use Gorilla Mux with App Engine. Here's how:

    At the end of the handlers section of app.yaml, add a script handler that routes all paths to the Go application:

    application: myapp
    version: 1
    runtime: go
    api_version: go1
    
    handlers:
    
    - url: /(.*\.(gif|png|jpg))$
      static_files: static/\1
      upload: static/.*\.(gif|png|jpg)$
    
    - url: /.*
      script: _go_app
    

    The _go_app script is the Go program compiled by App Engine. The pattern /.* matches all paths.

    The main function generated by App Engine dispatches all requests to the DefaultServeMux.

    In an init() function, create and configure a Gorilla Router. Register the Gorilla router with the DefaultServeMux to handle all paths:

    func init() {
        r := mux.NewRouter()
        r.HandleFunc("/", homeHandler)
    
        // The path "/" matches everything not matched by some other path.
        http.Handle("/", r)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号