问题描述
我在这里看到他们没有指定使用任何路由器...:
在Google Cloud与Golang一起使用时,它表示指定 app.yaml
中的每个处理程序。这是否意味着我们不应该使用第三方路由器来获得更好的性能?我想为路由器提供Gorilla Mux
...如果我为Google App Engine Golang应用程序使用其他路由器,它将如何工作?
请让我知道。感谢!
您可以使用App Engine的Gorilla Mux。方法如下:
在。注册Gorilla路由器与DefaultServeMux来处理所有路径:
pre $ func init(){
r:= mux.NewRouter ()
r.HandleFunc(/,homeHandler)
//路径/匹配与其他路径不匹配的所有内容。
http.Handle(/,r)
}
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!
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)
}
这篇关于Google Cloud Go处理程序没有路由器Gorilla Mux?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!