Google Cloud Go Handler without Gorilla Mux Router?

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

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

On Google Cloud, when used with Golang, it lists each handler in app.yaml . Does this mean that we should not use a third-party router to improve performance? I would like Gorilla Mux for the router ... How does it work if I use other routers for the Google App Engine Golang app?

Please let me know. Thanks!

+8
google-app-engine go router
source share
1 answer

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

At the end of the app.yaml handlers section, 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 

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

The main function created by App Engine sends all DefaultServeMux requests.

In the init () function, create and configure a Gorilla Router . Register your Gorilla router with 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) } 
+8
source share

All Articles