Help us shape the future of Go! Take the 2026 Go Developer Survey

banter

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2016 License: BSD-3-Clause Imports: 3 Imported by: 0

README

banter

httprouter + alice-like middleware = go web framework

Usage

Your middleware and route handlers can have the same function signature:

func customMiddleware(res http.ResponseWriter, req *http.Request) {
  // Do something before the final handler executes...
}

func handler(res http.ResponseWriter, req *http.Request) {
  // URL params (like :id) are added as query params
  fmt.Fprintf(res, "The resource ID is: %s", req.Query().Get("id"))
}

Create a router, configure it, and run it:

// Create a router.
router := banter.Router()

// Configure global middleware.
router.Use(cors.Default().Handler, logger.New)

// Configure a route with route-specific middleware and handlers.
router.GET("/thing/:id", customMiddleware, nosurf.NewPure, handler)

// Run the server.
http.ListenAndServe(":8080", router)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(chain *alice.Chain, middleware []interface{}) alice.Chain

Chain TODO

Types

type HTTPHandler

type HTTPHandler struct {
	Handler http.Handler
}

HTTPHandler TODO

func (HTTPHandler) Constructor

func (h HTTPHandler) Constructor(handler http.Handler) http.Handler

Constructor TODO

type HTTPRouter

type HTTPRouter struct {
	Router *httprouter.Router
	Chain  alice.Chain
}

HTTPRouter TODO

func Router

func Router() *HTTPRouter

Router TODO

func (*HTTPRouter) AddHandlers

func (r *HTTPRouter) AddHandlers(
	method string,
	path string,
	middleware []interface{},
)

AddHandlers TODO

func (*HTTPRouter) DELETE

func (r *HTTPRouter) DELETE(path string, middleware ...interface{})

DELETE is a shortcut for router.AddHandler("DELETE", path, handle)

func (*HTTPRouter) GET

func (r *HTTPRouter) GET(path string, middleware ...interface{})

GET is a shortcut for router.AddHandler("GET", path, handle)

func (*HTTPRouter) HEAD

func (r *HTTPRouter) HEAD(path string, middleware ...interface{})

HEAD is a shortcut for router.AddHandler("HEAD", path, handle)

func (*HTTPRouter) OPTIONS

func (r *HTTPRouter) OPTIONS(path string, middleware ...interface{})

OPTIONS is a shortcut for router.AddHandler("OPTIONS", path, handle)

func (*HTTPRouter) PATCH

func (r *HTTPRouter) PATCH(path string, middleware ...interface{})

PATCH is a shortcut for router.AddHandler("PATCH", path, handle)

func (*HTTPRouter) POST

func (r *HTTPRouter) POST(path string, middleware ...interface{})

POST is a shortcut for router.AddHandler("POST", path, handle)

func (*HTTPRouter) PUT

func (r *HTTPRouter) PUT(path string, middleware ...interface{})

PUT is a shortcut for router.AddHandler("PUT", path, handle)

func (*HTTPRouter) ServeHTTP

func (r *HTTPRouter) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP TODO

func (*HTTPRouter) Use

func (r *HTTPRouter) Use(middleware ...interface{})

Use TODO

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL