zeus

package module
v0.0.0-...-49dfdf6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2016 License: MIT Imports: 2 Imported by: 10 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Zeus

Zeus is a super-duper, simple and fast HTTP router for Go, nothing more, nothing less.

Install
go get github.com/daryl/zeus
Usage
package main

import (
    "fmt"
    "github.com/daryl/zeus"
    "net/http"
)

func main() {
    mux := zeus.New()
    // Supports named parameters.
    mux.GET("/users/:id", showUser)
    // Supports wildcards anywhere.
    mux.GET("/foo/*", catchFoo)
    // Custom 404 handler.
    mux.NotFound = notFound
    // Listen and serve.
    mux.Listen(":4545")
}

func showUser(w http.ResponseWriter, r *http.Request) {
    var id string

    // Get a map of all
    // route variables.
    vm := zeus.Vars(r)

    id = vm["id"]

    // Or just one.
    id = zeus.Var(r, "id")

    fmt.Fprintf(w, "User ID: %s", id)
}

func catchFoo(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Gotta catch 'em all"))
}

func notFound(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Nothing to see here"))
}
Documentation

For further documentation, check out GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Var

func Var(r *http.Request, n string) string

Get route variable from the current request.

func Vars

func Vars(r *http.Request) map[string]string

Get route variables for the current request.

Types

type Handler

type Handler struct {
	http.HandlerFunc
	// contains filtered or unexported fields
}

Handler contains the pattern and handler func.

type Mux

type Mux struct {
	NotFound http.HandlerFunc
	// contains filtered or unexported fields
}

Mux contains a map of handlers and the NotFound handler func.

func New

func New() *Mux

New returns a new Mux instance.

func (*Mux) DELETE

func (m *Mux) DELETE(patt string, handler http.HandlerFunc)

DELETE adds a new route for DELETE requests.

func (*Mux) GET

func (m *Mux) GET(patt string, handler http.HandlerFunc)

GET adds a new route for GET requests.

func (*Mux) HEAD

func (m *Mux) HEAD(patt string, handler http.HandlerFunc)

HEAD adds a new route for HEAD requests.

func (*Mux) Listen

func (m *Mux) Listen(port string)

Listen is a shorthand way of doing http.ListenAndServe.

func (*Mux) OPTIONS

func (m *Mux) OPTIONS(patt string, handler http.HandlerFunc)

OPTIONS adds a new route for OPTIONS requests.

func (*Mux) PATCH

func (m *Mux) PATCH(patt string, handler http.HandlerFunc)

PATCH adds a new route for PATCH requests.

func (*Mux) POST

func (m *Mux) POST(patt string, handler http.HandlerFunc)

POST adds a new route for POST requests.

func (*Mux) PUT

func (m *Mux) PUT(patt string, handler http.HandlerFunc)

PUT adds a new route for PUT requests.

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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