Google Cloud Go处理程序没有路由器Gorilla Mux? [英] Google Cloud Go Handler without Router Gorilla Mux?
问题描述
https://cloud.google.com/appengine/docs/go/users /
我在这里看到他们没有指定使用任何路由器...: https://cloud.google.com/appengine/docs/go/config/appconfig
在Google Cloud与Golang一起使用时,它表示指定 app.yaml
中的每个处理程序。这是否意味着我们不应该使用第三方路由器来获得更好的性能?我想为路由器提供Gorilla Mux
...如果我为Google App Engine Golang应用程序使用其他路由器,它将如何工作?
请让我知道。感谢!
您可以使用App Engine的Gorilla Mux。方法如下:
在 _go_app 脚本是由App Engine编译的Go程序。 App Engine生成的主函数将所有请求分派给<在一个init()函数中,我们使用了一个名为init()的函数,功能,创建并配置Gorilla 路由器。注册Gorilla路由器与DefaultServeMux来处理所有路径: 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 Please let me know. Thanks! 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: The 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:
这篇关于Google Cloud Go处理程序没有路由器Gorilla Mux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
application:myapp
版本:1
运行时:go
api_version:go1
处理程序:
- url:/(。 * \。(gif | png | jpg))$
static_files:static / \ 1
upload:static /.* \。(gif | png | jpg)$
- url:/.*
script:_go_app
/.*
模式匹配所有路径。
pre $ func init(){
r:= mux.NewRouter ()
r.HandleFunc(/,homeHandler)
//路径/匹配与其他路径不匹配的所有内容。
http.Handle(/,r)
}
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?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
_go_app
script is the Go program compiled by App Engine. The pattern /.*
matches all paths.func init() {
r := mux.NewRouter()
r.HandleFunc("/", homeHandler)
// The path "/" matches everything not matched by some other path.
http.Handle("/", r)
}