Skip to content

jeremyctrl/httprouter

httprouter

Go Reference License: MIT

A tiny, fast HTTP router powered by minimal perfect hashes.

httprouter is a compact router that compiles route templates into minimal-perfect-hash tables at build time so lookups are constant-time.

Get

go get github.com/jeremyctrl/httprouter

Example

package main

import (
    "fmt"
    "log"
    "net/http"

    "github.com/jeremyctrl/httprouter"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
	router := httprouter.New().
		GET("/", Index).
		GET("/hello/:name", Hello).
		Build()

	log.Fatal(http.ListenAndServe(":8080", router))
}

About

A tiny, fast HTTP router powered by minimal perfect hashes

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages