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 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态