[Go][Server] minor enhancement to the template (#4417)

* minor enhancement to the go server template

* update samples
This commit is contained in:
William Cheng 2019-11-09 11:24:12 +08:00 committed by GitHub
parent 777e39007a
commit db729be7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 37 deletions

View File

@ -7,9 +7,9 @@ import (
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
{{#featureCORS}} {{#featureCORS}}
"github.com/gorilla/handlers"
"github.com/gorilla/handlers"{{/featureCORS}} {{/featureCORS}}
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -36,8 +36,10 @@ func NewRouter(routers ...Router) *mux.Router {
for _, route := range api.Routes() { for _, route := range api.Routes() {
var handler http.Handler var handler http.Handler
handler = route.HandlerFunc handler = route.HandlerFunc
handler = Logger(handler, route.Name){{#featureCORS}} handler = Logger(handler, route.Name)
handler = handlers.CORS()(handler){{/featureCORS}} {{#featureCORS}}
handler = handlers.CORS()(handler)
{{/featureCORS}}
router. router.
Methods(route.Method). Methods(route.Method).

View File

@ -15,7 +15,6 @@ import (
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )