Documentation
¶
Overview ¶
go_router is a simple rest based router. The supported HTTP methods are GET, POST and DELETE. The url path has to be in the form `/version/resource/handler/param-name/param-value`.
Json is the supported response type. It also supports the use of filters for pre and post dispatch process.
@author: avarghese
Index ¶
Constants ¶
View Source
const (
JSON = "application/json"
)
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch(w http.ResponseWriter, r *http.Request)
Dispatch a Request. Only supports json responses.
Usage: http.HandleFunc("/", router.Dispatch) http.ListenAndServe(":8080", nil)
func RegisterRoute ¶
Register a route. Parameters required are http method, url path and a controller.
Usage: go_router.RegisterRoute(GET, "/v1/test/retrieve", test_controller.Retrieve) go_router.RegisterRoute(POST, "/v1/test/save", test_controller.Save)
Types ¶
type Filter ¶
type Filter interface { Name() string PreDispatch(*http.Request, Request) error PostDispatch(*http.Request, Request) error }
Filters allow for pre and post dispatch work. For example verifying api key.
type Node ¶
type Node interface{}
Node is a controller function. The function should have a pointer to all required request parameters. Returns an interface and an error. Example:
type Test struct { Id int64 } func GetUser(t *Test) (string, error) { fmt.Println(t) return "user", nil }
type Request ¶
type Request map[string]*RequestParam
type RequestParam ¶
type RequestParam struct {
Value interface{}
}
Click to show internal directories.
Click to hide internal directories.