top
(README.md)
bone [![GoDoc](https://godoc.org/github.com/squiidz/bone?status.png)](http://godoc.org/github.com/go-zoo/bone) [![Build Status](https://travis-ci.org/go-zoo/bone.svg)](https://travis-ci.org/go-zoo/bone) [![Go Report Card](https://goreportcard.com/badge/go-zoo/bone)](https://goreportcard.com/report/go-zoo/bone)
=======

## What is bone ?

Bone is a lightweight and lightning fast HTTP Multiplexer for Golang. It support :

- URL Parameters
- REGEX Parameters
- Wildcard routes
- Router Prefix
- Sub Router, `mux.SubRoute()`, support most standard router (bone, gorilla/mux, httpRouter etc...)
- Http method declaration
- Support for `http.Handler` and `http.HandlerFunc`
- Custom NotFound handler
- Respect the Go standard `http.Handler` interface

![alt tag](https://c2.staticflickr.com/2/1070/540747396_5542b42cca_z.jpg)

## Speed

```
- BenchmarkBoneMux        10000000               118 ns/op
- BenchmarkZeusMux          100000               144 ns/op
- BenchmarkHttpRouterMux  10000000               134 ns/op
- BenchmarkNetHttpMux      3000000               580 ns/op
- BenchmarkGorillaMux       300000              3333 ns/op
- BenchmarkGorillaPatMux   1000000              1889 ns/op
```

 These test are just for fun, all these router are great and really efficient.
 Bone do not pretend to be the fastest router for every job.

## Example

``` go

package main

import(
  "net/http"

  "github.com/go-zoo/bone"
)

func main () {
  mux := bone.New()

  // mux.Get, Post, etc ... takes http.Handler
  mux.Get("/home/:id", http.HandlerFunc(HomeHandler))
  mux.Get("/profil/:id/:var", http.HandlerFunc(ProfilHandler))
  mux.Post("/data", http.HandlerFunc(DataHandler))

  // Support REGEX Route params
  mux.Get("/index/#id^[0-9]$", http.HandleFunc(IndexHandler))

  // Handle take http.Handler
  mux.Handle("/", http.HandlerFunc(RootHandler))

  // GetFunc, PostFunc etc ... takes http.HandlerFunc
  mux.GetFunc("/test", Handler)

  http.ListenAndServe(":8080", mux)
}

func Handler(rw http.ResponseWriter, req *http.Request) {
  // Get the value of the "id" parameters.
  val := bone.GetValue(req, "id")

  rw.Write([]byte(val))
}

```
## Changelog

#### Update 25 September 2015

- Add support for Sub router

Example :
``` go
func main() {
    mux := bone.New()
    sub := mux.NewRouter()

    sub.GetFunc("/test/example", func(rw http.ResponseWriter, req *http.Request) {
        rw.Write([]byte("From sub router !"))
    })

    mux.SubRoute("/api", sub)

    http.ListenAndServe(":8080", mux)
}

```


#### Update 26 April 2015

- Add Support for REGEX parameters, using ` # ` instead of ` : `.
- Add Mux method ` mux.GetFunc(), mux.PostFunc(), etc ... `, takes ` http.HandlerFunc ` instead of ` http.Handler `.

Example :
``` go
func main() {
    mux.GetFunc("/route/#var^[a-z]$", handler)
}

func handler(rw http.ResponseWriter, req *http.Request) {
    bone.GetValue(req, "var")
}
```

#### Update 29 january 2015

- Speed improvement for url Parameters, from ```~ 1500 ns/op ``` to ```~ 1000 ns/op ```.

#### Update 25 december 2014

After trying to find a way of using the default url.Query() for route parameters, i decide to change the way bone is dealing with this. url.Query() is too slow for good router performance.
So now to get the parameters value in your handler, you need to use
` bone.GetValue(req, key) ` instead of ` req.Url.Query().Get(key) `.
This change give a big speed improvement for every kind of application using route parameters, like ~80x faster ...
Really sorry for breaking things, but i think it's worth it.  

## TODO

- DOC
- More Testing
- Debugging
- Optimisation

## Contributing

1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)
3. Write Tests!
4. Commit your changes (git commit -am 'Add some feature')
5. Push to the branch (git push origin my-new-feature)
6. Create new Pull Request

## License
MIT

## Links
- Blog post talking about bone : http://www.peterbe.com/plog/my-favorite-go-multiplexer

## Libs
- Errors dump for Go : [Trash](https://github.com/go-zoo/trash)
- Middleware Chaining module : [Claw](https://github.com/go-zoo/claw)

Imported by 138 package(s)

  1. github.com/14rcole/cri-o/server
  2. github.com/1851616111/go-http-routing-benchmark
  3. github.com/AchievementNetwork/go-util/boneful
  4. github.com/AchievementNetwork/static
  5. github.com/AndrewBurian/go-http-routing-benchmark
  6. github.com/BPing/go-web-framework-benchmark
  7. github.com/CloudyKit/go-http-routing-benchmark
  8. github.com/JessonChan/go-http-routing-benchmark
  9. github.com/Jimmy99/go-http-routing-benchmark
  10. github.com/JulienSchmidt/go-http-routing-benchmark
  11. github.com/JustAdam/deployer
  12. github.com/MatejLach/hoverfly
  13. github.com/ObjectIsAdvantag/hoverfly
  14. github.com/SpectoLabs/hoverfly/core
  15. github.com/SpectoLabs/hoverfly/core/handlers
  16. github.com/SpectoLabs/hoverfly/core/handlers/v1
  17. github.com/SpectoLabs/hoverfly/core/handlers/v2
  18. github.com/SpectoLabs/twitter-app
  19. github.com/ThatsMrTalbot/example
  20. github.com/TheHippo/go-http-routing-benchmark
  21. github.com/ValleyCamp/WeatherMoss
  22. github.com/Xuyuanp/go-http-routing-benchmark
  23. github.com/achiku/sample-golang-bone-context
  24. github.com/achiku/sample-golang-logging
  25. github.com/achiku/sample-golang-newrelic
  26. github.com/achiku/sample-golang-xhandler
  27. github.com/andrewburian/go-http-routing-benchmark
  28. github.com/ant0ine/go-http-routing-benchmark
  29. github.com/arthurwhite/go-http-routing-benchmark
  30. github.com/beauhoyt/go-http-routing-benchmark
  31. github.com/besser/go-http-routing-benchmark
  32. github.com/betacraft/deferclient/deferstats
  33. github.com/betacraft/lemonade
  34. github.com/betacraft/lemonade/controllers
  35. github.com/betacraft/lemonade/interceptors
  36. github.com/bfitzsimmons/go-http-routing-benchmark
  37. github.com/bspaans/hoverfly
  38. github.com/chubais/go-http-routing-benchmark
  39. github.com/citysir/go-http-routing-benchmark
  40. github.com/claygod/go-web-framework-benchmark
  41. github.com/coderhaoxin/chai
  42. github.com/cvvs/badb
  43. github.com/dalent/go-http-routing-benchmark
  44. github.com/daniel-bryant-uk/hoverfly
  45. github.com/danielbryantuk/hoverfly
  46. github.com/dimiro1/experiments/bone
  47. github.com/dinever/go-http-routing-benchmark
  48. github.com/djinn/go-http-routing-benchmark
  49. github.com/edgexfoundry/edgex-go/export/client
  50. github.com/edgexfoundry/edgex-go/export/distro
  51. github.com/edgexfoundry/edgex-go/support/logging
  52. github.com/edgexfoundry/export-go/client
  53. github.com/edgexfoundry/export-go/distro
  54. github.com/evepraisal/go-evepraisal/web
  55. github.com/fairway-corp/swagchat-api/handlers
  56. github.com/generationtux/brizo/app/handlers/api
  57. github.com/generationtux/brizo/app/routes
  58. github.com/gerryyang/go-http-routing-benchmark
  59. github.com/gin-gonic/go-http-routing-benchmark
  60. github.com/gnanderson/go-http-routing-benchmark
  61. github.com/go-gas/go-web-framework-benchmark
  62. github.com/go-zoo/bone/example/001
  63. github.com/go-zoo/bone/example/002
  64. github.com/go-zoo/bone/example/003
  65. github.com/go-zoo/bone/example/004
  66. github.com/gofury/go-web-framework-benchmark
  67. github.com/gotokatsuya/go-http-routing-benchmark
  68. github.com/guerrero/blog
  69. github.com/guerrero/blog/controllers
  70. github.com/ingenieux/codecommit-package-server
  71. github.com/jbuberel/go-http-routing-benchmark
  72. github.com/joeybloggs/go-http-routing-benchmark
  73. github.com/julienschmidt/go-http-routing-benchmark
  74. github.com/jwhonce/cri-o/server
  75. github.com/kdada/go-http-routing-benchmark
  76. github.com/kdada/go-web-framework-benchmark
  77. github.com/kentquirk/boneful
  78. github.com/l3pp4rd/go-http-routing-benchmark
  79. github.com/liu-rui/go-http-routing-benchmark
  80. github.com/liu-rui/go-web-framework-benchmark
  81. github.com/lunny/go-http-routing-benchmark
  82. github.com/lvzhihao/go-web-framework-benchmark
  83. github.com/manifoldco/grafton/connector
  84. github.com/manifoldco/torus-cli/daemon/routes
  85. github.com/manifoldco/torus-cli/daemon/socket
  86. github.com/manifoldco/torus-cli/gatekeeper/http
  87. github.com/massa142/go-frameworks-benchmark
  88. github.com/matthewdu/powerplug
  89. github.com/matthewdu/rule110-go
  90. github.com/mikespook/go-http-routing-benchmark
  91. github.com/mozey/hoverfly
  92. github.com/najeira/go-frameworks-benchmark
  93. github.com/noypi/go-http-routing-benchmark
  94. github.com/noypi/kv/proxy
  95. github.com/nrwiersma/ren/server
  96. github.com/pegasuskim/go-http-routing-benchmark
  97. github.com/pkg4go/chai
  98. github.com/pkieltyka/go-http-routing-benchmark
  99. github.com/qiangxue/go-http-routing-benchmark
  100. github.com/rhatdan/cri-o/server
  101. github.com/ricorx7/go-vault
  102. github.com/rusenask/bikend
  103. github.com/rusenask/genproxy
  104. github.com/rusenask/hoverfly
  105. github.com/rusenask/lgc
  106. github.com/rusenask/overseer
  107. github.com/safeie/go-http-routing-benchmark
  108. github.com/shivakar/go-http-routing-benchmark
  109. github.com/smallnest/go-web-framework-benchmark
  110. github.com/smashedtoatoms/codecommit-package-server
  111. github.com/solher/auth-nginx-proxy-companion/app
  112. github.com/solher/auth-nginx-proxy-companion/infrastructure
  113. github.com/solher/kit-gateway
  114. github.com/solher/kit-gateway/library
  115. github.com/solher/zest
  116. github.com/squiidz/bench
  117. github.com/squiidz/fishMe
  118. github.com/squiidz/ghosterize
  119. github.com/squiidz/mtlsoft
  120. github.com/squiidz/spammer
  121. github.com/squiidz/spoon
  122. github.com/squiidz/spoon/api
  123. github.com/suifengRock/go-http-routing-benchmark
  124. github.com/sunisdown/go-http-routing-benchmark
  125. github.com/swagchat/chat-api/handlers
  126. github.com/taka-wang/mb-web/route
  127. github.com/theckman/go-http-routing-benchmark
  128. github.com/twanies/go-http-routing-benchmark
  129. github.com/ursiform/go-http-routing-benchmark
  130. github.com/valleycamp/WeatherMoss
  131. github.com/vanng822/go-http-routing-benchmark
  132. github.com/viniciusfeitosa/GoInRIO
  133. github.com/viniciusfeitosa/GoInRIO/handlers
  134. github.com/viniciusfeitosa/GoInRio/handlers
  135. github.com/wenkesj/go-server
  136. github.com/wenkesj/go-server/httpserver
  137. github.com/wking/cri-o/server
  138. github.com/yudppp/go-frameworks-benchmark

Imported only in test by 4 package(s)

  1. github.com/davyzhang/agw
  2. github.com/taka-wang/mb-socket/worker
  3. github.com/taka-wang/mb-web/test
  4. github.com/taka-wang/mb-web/worker