All Downloads are FREE. Search and download functionalities are using the official Maven repository.

go-server.routers.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
{{>partial_header}}
package {{packageName}}

import (
	"fmt"
	"net/http"
	"strings"

	"github.com/gorilla/mux"
)

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

type Routes []Route

func NewRouter() *mux.Router {
	router := mux.NewRouter().StrictSlash(true)
	for _, route := range routes {
		var handler http.Handler
		handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}

	return router
}

func Index(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello World!")
}

var routes = Routes{
	Route{
		"Index",
		"GET",
		"{{{basePathWithoutHost}}}/",
		Index,
	},{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}

	Route{
		"{{operationId}}",
		strings.ToUpper("{{httpMethod}}"),
		"{{{basePathWithoutHost}}}{{{path}}}",
		{{operationId}},
	},{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy