File: router.go

package info (click to toggle)
golang-github-manyminds-api2go 1.0-RC2%2Bgit20161229.31.dc368bb-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 484 kB
  • ctags: 488
  • sloc: sh: 23; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 874 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package routing

import "net/http"

// HandlerFunc must contain all params from the route
// in the form key,value
type HandlerFunc func(w http.ResponseWriter, r *http.Request, params map[string]string)

// Routeable allows drop in replacement for api2go's router
// by default, we are using julienschmidt/httprouter
// but you can use any router that has similiar features
// e.g. gin
type Routeable interface {
	// Handler should return the routers main handler, often this is the router itself
	Handler() http.Handler
	// Handle must be implemented to register api2go's default routines
	// to your used router.
	// protocol will be PATCH,OPTIONS,GET,POST,PUT
	// route will be the request route /items/:id where :id means dynamically filled params
	// handler is the handler that will answer to this specific route
	Handle(protocol, route string, handler HandlerFunc)
}