koala

package module
v0.0.0-...-2e591dd Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2016 License: MIT Imports: 5 Imported by: 0

README

koala Build Status GoDoc

lightweight multiplexer for Go

install

$ go get "github.com/haochi/koala"
package main

import (
	"github.com/haochi/koala"
	"net/http"
	"fmt"
)

func main() {
	app := koala.New()

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

	app.Get("/~{id}", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "user %s reporting for duty!", koala.Param(r, "id"))
	})

	panic(http.ListenAndServe(":8080", app))
}

Documentation

Overview

koala is a simple multiplexer for go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Param

func Param(request *http.Request, key string) string

Get the resolved route parameter with the given key

func Params

func Params(request *http.Request) map[string]string

Get all the resolved route parameters

Types

type Mux

type Mux struct {
	NotFoundHandler http.Handler // Handler when no routes are matched. Defaults to `http.NotFoundHandler`
	// contains filtered or unexported fields
}

func New

func New() *Mux

Create a new mux

func (*Mux) AddRoute

func (mux *Mux) AddRoute(method string, path string, handlerFunc http.HandlerFunc) *Mux

Add a new route

func (*Mux) AddRouteHandler

func (mux *Mux) AddRouteHandler(method string, path string, handler http.Handler) *Mux

func (*Mux) Delete

func (mux *Mux) Delete(path string, handlerFunc http.HandlerFunc) *Mux

Short hand for AddRoute("DELETE", path, handlerFunc)

func (*Mux) DeleteHandler

func (mux *Mux) DeleteHandler(path string, handler http.Handler) *Mux

Short hand for AddRouteHandler("DELETE", path, handler)

func (*Mux) Get

func (mux *Mux) Get(path string, handlerFunc http.HandlerFunc) *Mux

Short hand for AddRoute("GET", path, handlerFunc)

func (*Mux) GetHandler

func (mux *Mux) GetHandler(path string, handler http.Handler) *Mux

Short hand for AddRouteHandler("GET", path, handler)

func (*Mux) Post

func (mux *Mux) Post(path string, handlerFunc http.HandlerFunc) *Mux

Short hand for AddRoute("POST", path, handlerFunc)

func (*Mux) PostHandler

func (mux *Mux) PostHandler(path string, handler http.Handler) *Mux

Short hand for AddRouteHandler("POST", path, handler)

func (*Mux) Put

func (mux *Mux) Put(path string, handlerFunc http.HandlerFunc) *Mux

Short hand for AddRoute("PUT", path, handlerFunc)

func (*Mux) PutHandler

func (mux *Mux) PutHandler(path string, handler http.Handler) *Mux

Short hand for AddRouteHandler("PUT", path, handler)

func (*Mux) ServeHTTP

func (mux *Mux) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Serve HTTP

type Route

type Route struct {
	// contains filtered or unexported fields
}

func NewRoute

func NewRoute(method string, path string, handler http.Handler) *Route

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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