Skip to content
/ mux Public

A minimal but feature-rich HTTP router for Go

License

Notifications You must be signed in to change notification settings

livebud/mux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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