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

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

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
Comments
  • 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)
    }
    
  • 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

  • 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:

  • 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

  • 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]
    }
    
  • Make *filepath optionally match

    Make *filepath optionally match

    I decided to use your library in a new project and discovered that if I have a route for /:name/tree/:ref/*path but the request path is only /foo/tree/main the route isn't matched and 404(s). I had to add an empty route for /:name/tree/:ref for things to work.

    Can we make matching optional in this case? It seems logical that a *path indicate anything or nothing.

  • 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

  • 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).

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).
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

Jan 1, 2023
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

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

Dec 30, 2022
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

Jan 8, 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

Dec 12, 2021
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

Aug 14, 2022
gnark is a fast, open-source library for zero-knowledge proof protocols written in Go
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

Jan 1, 2023
gnark is a fast, open-source library for zero-knowledge proof protocols written in Go
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

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/

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

Sep 2, 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.
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

Dec 28, 2022
Fast and Reliable Golang Web Framework
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

Dec 18, 2022
Gin is a HTTP web framework written in Go (Golang).
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.

Jan 3, 2023
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 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项目或者执行其他操作。

Jan 5, 2023
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
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

May 31, 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

Nov 8, 2022
Dec 28, 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

Jan 2, 2023