add custom js functions for templates
This commit is contained in:
28
examples/custom-js-functions/templates/router.tmpl
Normal file
28
examples/custom-js-functions/templates/router.tmpl
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"your-app/controllers"
|
||||
)
|
||||
|
||||
{{formatComment "Router setup with all entity routes\nGenerated using custom JavaScript template functions"}}
|
||||
func SetupRouter() *mux.Router {
|
||||
router := mux.NewRouter()
|
||||
|
||||
{{range $entity := .AST.Definitions}}
|
||||
{{- if $entity.Entity}}
|
||||
{{formatComment (printf "Routes for %s entity" $entity.Entity.Name)}}
|
||||
{{$entity.Entity.Name | lower}}Controller := controllers.New{{$entity.Entity.Name | title}}Controller()
|
||||
router.HandleFunc("/{{pluralize ($entity.Entity.Name | lower)}}", {{$entity.Entity.Name | lower}}Controller.List{{pluralize ($entity.Entity.Name | title)}}).Methods("GET")
|
||||
router.HandleFunc("/{{pluralize ($entity.Entity.Name | lower)}}/:id", {{$entity.Entity.Name | lower}}Controller.Get{{$entity.Entity.Name | title}}).Methods("GET")
|
||||
router.HandleFunc("/{{pluralize ($entity.Entity.Name | lower)}}", {{$entity.Entity.Name | lower}}Controller.Create{{$entity.Entity.Name | title}}).Methods("POST")
|
||||
router.HandleFunc("/{{pluralize ($entity.Entity.Name | lower)}}/:id", {{$entity.Entity.Name | lower}}Controller.Update{{$entity.Entity.Name | title}}).Methods("PUT")
|
||||
router.HandleFunc("/{{pluralize ($entity.Entity.Name | lower)}}/:id", {{$entity.Entity.Name | lower}}Controller.Delete{{$entity.Entity.Name | title}}).Methods("DELETE")
|
||||
|
||||
{{end}}
|
||||
{{- end}}
|
||||
|
||||
return router
|
||||
}
|
Reference in New Issue
Block a user