Muxie is a modern, fast and light HTTP multiplexer for Go. Fully compatible with the http.Handler interface. Written for everyone.

Overview

Muxie

🚂 🚋 🚋 🚋 🚋 🚋
Fast trie implementation designed from scratch specifically for HTTP
A small and light router for creating sturdy backend Go applications. Production-level tested, muxie's capabilities live inside the well-tested Iris web framework.

The little router that could. Built with ❤︎ by Gerasimos Maropoulos

Benchmark chart between muxie, httprouter, gin, gorilla mux, echo, vestigo and chi FOSSA Status

Last updated on October 17, 2018. Click here to read more details.

Features

  • trie based: performance and useness are first class citizens, Muxie is based on the prefix tree data structure, designed from scratch and built for HTTP, and it is among the fastest outhere, if not the fastest one
  • grouping: group common routes based on their path prefixes
  • no external dependencies: weighing 30kb, Muxie is a tiny little library without external dependencies
  • closest wildcard resolution and prefix-based custom 404: wildcards, named parameters and static paths can all live and play together nice and fast in the same path prefix or suffix(!)
  • small api: with only 3 main methods for HTTP there's not much to learn
  • compatibility: built to be 100% compatible with the net/http standard package

Technical Features

  • Closest Wildcard Resolution and Root wildcard (CWR)*
  • Parameterized Dynamic Path (named parameters with :name and wildcards with *name, can play all together for the same path prefix|suffix)*
  • Standard handlers chain (Pre(handlers).For(mainHandler) for individual routes and Mux#Use for router)*
  • Register handlers by method(s) (muxie.Methods())*
  • Register handlers by filters (Mux#HandleRequest and Mux#AddRequestHandler for muxie.Matcher and muxie.RequestHandler)
  • Handle subdomains with ease (muxie.Host Matcher)*
  • Request Processors (muxie.Bind and muxie.Dispatch)*

Interested? Want to learn more about this library? Check out our tiny examples and the simple godocs page.

Installation

The only requirement is the Go Programming Language

$ go get -u github.com/kataras/muxie

License

MIT

FOSSA Status

Issues
  • Parameter key value is empty in my custom ResponseWriter

    Parameter key value is empty in my custom ResponseWriter

    Hi @kataras , I'm an Early user of muxie, it's a grace work. Today I want to write a middleware for my app and found the value of parameter key is empty. Could you help me get it?

    My codes:

    package main
    
    import (
    	"github.com/kataras/muxie"
    	"net/http"
    	"strconv"
    	"time"
    )
    
    func main() {
    	mux := muxie.NewMux()
    	mux.Use(RequestTime)
    
    	mux.HandleFunc("/hello/:name", func(w http.ResponseWriter, r *http.Request) {
    		name := muxie.GetParam(w, "name")
    		// here  len(name) == 0 
    		_, _ = w.Write([]byte("Hello :" + name))
    	})
    	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    		_, _ = w.Write([]byte("Hello\n"))
    	})
    
    	_ = http.ListenAndServe(":8082", mux)
    }
    
    type responseWriterWithTimer struct {
    	http.ResponseWriter
    	isHeaderWritten bool
    	start           time.Time
    }
    
    func RequestTime(next http.Handler) http.Handler {
    	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    		next.ServeHTTP(&responseWriterWithTimer{w, false, time.Now()}, r)
    	})
    }
    
    func (w *responseWriterWithTimer) WriteHeader(statusCode int) {
    	duration := time.Now().Sub(w.start)
    	us := int(duration.Truncate(1000*time.Nanosecond).Nanoseconds() / 1000)
    	w.Header().Set("X-Response-Time", strconv.Itoa(us)+" us")
    
    	w.ResponseWriter.WriteHeader(statusCode)
    	w.isHeaderWritten = true
    }
    
    func (w *responseWriterWithTimer) Write(b []byte) (int, error) {
    	if !w.isHeaderWritten {
    		w.WriteHeader(200)
    	}
    	return w.ResponseWriter.Write(b)
    }
    
    enhancement 
    opened by ego008 2
  • Why doesn't the http.ResposeWriter implement http.Flush

    Why doesn't the http.ResposeWriter implement http.Flush

    Given this test function:

    func test(w http.ResponseWriter, r *http.Request) {
    	_, ok := w.(http.Flusher)
    	fmt.Println(ok)
    }
    

    This returns true:

    func main() {
    	http.ListenAndServe(":8080", http.HandlerFunc(test))
    }
    

    This returns false:

    func main() {
    	mux := muxie.NewMux()
    	mux.HandleFunc("/*path", test)
    	http.ListenAndServe(":8080", mux)
    }
    

    Is there any reason why the http.RequestWriter does not implement http.Flusher? I absolutely need this feature for my usage of the router

    @kataras

    opened by lucat1 1
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • Remove excess redirect

    Remove excess redirect

    redirect from standard library correct work with GET

    https://github.com/golang/go/blob/9e277f7d554455e16ba3762541c53e9bfc1d8188/src/net/http/server.go#L2101-L2104

    opened by moeryomenko 0
  • some question of func: resolveStaticPart

    some question of func: resolveStaticPart

    https://github.com/kataras/muxie/blob/920ec04bf8a1c27fd7e921cd880d0495f74e1861/trie.go#L109

    Nice Repo!

    i wanna to study how to write a golang router, so i'm reading source code of mux, httprouter, and muxie.

    the following code, i think have some mistake.

    func resolveStaticPart(key string) string {
    	i := strings.Index(key, ParamStart)
    	if i == -1 {
    		i = strings.Index(key, WildcardParamStart)
    	}
    	if i == -1 {
    		i = len(key)
    	}
    
    	return key[:i]
    }
    

    what i think could be

    func minInt(x, y int) int {
    	if x < y {
    		return x
    	}
    	return y
    }
    
    func resolveStaticPart1(key string) string {
    	i := strings.Index(key, WildcardParamStart)
    	j := strings.Index(key, ParamStart)
    	min := minInt(i, j)
    	if -1 == min {
    		return key
    	}
    	return key[:min]
    }
    
    opened by chenkaiC4 0
  • websocket: response does not implement http.Hijacker

    websocket: response does not implement http.Hijacker

    Hi, I'm trying to use this library with WebSockets using https://github.com/gorilla/websocket, but I get this error when the server attempts to upgrade the connection.

    websocket: response does not implement http.Hijacker
    

    If I revert to the standard library with

    mux := http.NewServeMux()
    

    everything works fine

    question 
    opened by TommasoAmici 1
  • Handle OPTIONS method

    Handle OPTIONS method

    I added a simple way of handling OPTIONS automatically, when MethodHandler is in use.

    As a potential update, it should handle duplications gracefully (eg. one should be able to register a method to handle OPTIONS on their own).

    opened by julian7 1
Releases(v1.1.2)
  • v1.1.2(Feb 6, 2021)

  • v1.1.1(Jul 23, 2020)

  • v1.1.0(Jul 22, 2020)

  • v1.0.9(May 16, 2020)

  • v1.0.8(Dec 5, 2019)

  • v1.0.7(Feb 1, 2019)

    Changes: https://github.com/kataras/muxie/compare/v1.0.6...v1

    • Exported muxie.ResponseWriter completes the http.ResponseWriter and it is params setter/getter that end-devs can wrap to make compatible custom http response writers without losing the path parameters features.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.6(Nov 15, 2018)

  • v1.0.5(Oct 21, 2018)

  • v1.0.4(Oct 20, 2018)

    Changes: https://github.com/kataras/muxie/compare/v1.0.3...v1.0.4

    In short: Add support for fitlered request handlers, request_handler.go. See Mux#HandleRequest, muxie.Host Matcher and take a look at the example: https://github.com/kataras/muxie/tree/master/_examples/9_subdomains_and_matchers.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Oct 18, 2018)

    Changes: https://github.com/kataras/muxie/compare/v1.0.2...v1.0.3

    In short: Add request_processor.go, see muxie.JSON/XML and read /_examples/8_bind_req_send_resp.

    Also: Allow more than one methods to be passed on muxie.Methods().Handle/HandleFunc to register the same handler for specific methods.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Oct 18, 2018)

    Changes from v1.0.1: https://github.com/kataras/muxie/compare/v1.0.1...v1.0.2

    In short: Add the Methods().Handle(method string, handler http.Handler) and example.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Oct 17, 2018)

Owner
Gerasimos (Makis) Maropoulos
🥇 That Greek Gopher | 💨 Senior Backend Engineer at PNOĒ | 🎓My dream is to create an international IT university that will produce flawless developers!
Gerasimos (Makis) Maropoulos
henrylee2cn 1.6k Jun 26, 2022
A minimal framework to build web apps; with handler chaining, middleware support; and most of all standard library compliant HTTP handlers(i.e. http.HandlerFunc).

WebGo v4.1.3 WebGo is a minimalistic framework for Go to build web applications (server side) with zero 3rd party dependencies. Unlike full-fledged fr

Kamaleshwar 247 Jun 15, 2022
Timeout handler for http request in Gin framework

Middleware to Handle Request Timeout in Gin Installation Installation go get github.com/s-wijaya/gin-timeout Import it in your code: import ( // o

Saptari Wijaya 0 Dec 14, 2021
This library provides a simple framework of microservice, which includes a configurator, a logger, metrics, and of course the handler

Microservice The framework for the creation of microservices, written in Golang. (note: http microservice) Architecture microservice includes: handle

Eduard 97 Jun 26, 2022
GOLF(Go Light Filter), golf dependents Gorm and Gin.

GOLF (WIP) GOLF(Go Light Filter), golf dependents Gorm and Gin. golf can help you build model query as fast as,build model query like Django Rest Fram

1mtrue 4 Dec 12, 2021
Gin middleware/handler to enable CORS support.

wcors Gin middleware/handler to enable CORS support. Usage Start using it Download and install it: go get github.com/wyy-go/wcors Import it in your co

null 0 Jan 8, 2022
Golang based tools for taking PC-compatible ELFs and generating fake SELFs that run on the PlayStation 4.

Tool Documentation (create-fself) Summary create-fself can be used to take 64-bit ELF files and produce fake Signed ELFs that can be used on the PlayS

null 4 Jan 5, 2022
gnark is a fast, open-source library for zero-knowledge proof protocols written in Go

gnark gnark is a framework to execute (and verify) algorithms in zero-knowledge. It offers a high-level API to easily design circuits and fast impleme

ConsenSys Software 510 Jun 24, 2022
gnark is a fast, open-source library for zero-knowledge proof protocols written in Go

gnark gnark is a framework to execute (and verify) algorithms in zero-knowledge. It offers a high-level API to easily design circuits and fast impleme

ConsenSys Software 1.3k Jun 1, 2021
An example implementation of a REST interface in Golang using primarily the standard library.

REST API in Golang This is an example REST API implementation using primarily the standard library. The exceptions are as follows. github.com/gorilla/

Daniel 0 Jan 22, 2022
Best simple, lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqL Database and Clean Architecture

GOLANG FIBER API (CLEAN ARCHITECTURE) Best simple, lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqLDatabase using

Elias Champi 2 May 20, 2022
Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.

Ponzu Watch the video introduction Ponzu is a powerful and efficient open-source HTTP server framework and CMS. It provides automatic, free, and secur

Ponzu 5.5k Jun 29, 2022
Fast and Reliable Golang Web Framework

Gramework The Good Framework Gramework long-term testing stand metrics screenshot made with Gramework Stats Dashboard and metrics middleware What is i

null 368 Jun 11, 2022
Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Gin-Gonic 60.5k Jun 25, 2022
Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance. Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo(For English Documentation Click Here) 一个使用Go语言开发的web框架。 相关工具及插件 tiger tiger是一个专门为Tigo框架量身定做的脚手架工具,可以使用tiger新建Tigo项目或者执行其他操作。

Karl 1.3k Jun 28, 2022
Fastrest - fast restful framework for golang.

fastrest fast restful framework for golang. Create your app directory, like mkdir myapp; cd myapp; go mod init myapp; Create initial config.toml in a

bingoohuang 0 Jan 11, 2022
REST api using fiber framework written in golang and using firebase ecosystem to authentication, storage and firestore as a db and use clean architecture as base

Backend API Example FiberGo Framework Docs : https://github.com/gofiber Info This application using firebase ecosystem Firebase Auth Cloud Storage Fir

Atilla Pehlivan 3 May 31, 2022
QOR is a set of libraries written in Go that abstracts common features needed for business applications, CMSs, and E-commerce systems.

QOR English Chat Room: 中文聊天室: For security issues, please send us an email to [email protected] and give us time to respond BEFORE posting as an iss

QOR 5k Jun 28, 2022
go-zero is a web and rpc framework written in Go. It's born to ensure the stability of the busy sites with resilient design. Builtin goctl greatly improves the development productivity.

go-zero English | 简体中文 0. what is go-zero go-zero is a web and rpc framework that with lots of engineering practices builtin. It’s born to ensure the

好未来技术 18.7k Jun 26, 2022