Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.17 KB

Readme.md

File metadata and controls

53 lines (38 loc) · 1.17 KB

Mux

Go Reference

A minimal but feature-rich HTTP router for Go. A viable alternative to gorilla/mux.

Features

  • Trie-based router for better performance
  • Supports required, optional, regexp and wildcard slots
  • Smart slot delimiters (e.g. can match /{from}-{to})
  • Well-tested with 100s of tests

Install

go get github.com/livebud/mux

Example

package main

import (
	"net/http"

	"github.com/livebud/mux"
)

func main() {
  handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte(r.URL.Path))
  })
  router := mux.New()
  router.Get("/", handler)
  router.Get("/users/{id}", handler)
  router.Post("/users/{id}.{format}", handler)
  router.Get("/posts/{post_id}/comments/{id}", handler)
  router.Get("/fly/{from}-{to}", handler)
  router.Get("/v{major|[0-9]+}.{minor|[0-9]+}", handler)
  router.Get("/{owner}/{repo}/{branch}/{path*}", handler)
  http.ListenAndServe(":3000", router)
}

Contributors

License

MIT