BoneHTTP 多路复用器

联合创作 · 2023-09-29 08:43

Bone 是一个轻量级、非常快速的 HTTP 多路复用器,支持 URL 变量、HTTP 方法声明和自定义 NotFound 处理器。

alt tag

Speed

- BenchmarkBoneMux        10000000               118 ns/op
- BenchmarkZeusMux          100000             54813 ns/op
- BenchmarkHttpRouterMux  10000000               143 ns/op
- BenchmarkNetHttpMux      3000000               548 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. ]

Example

package main

import(
  "net/http"

  "github.com/squiidz/bone"
)

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

  // Method takes http.HandlerFunc
  mux.Get("/home/:id", HomeHandler)
  mux.Post("/data", DataHandler)

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

  http.ListenAndServe(":8080", mux)
}
浏览 1
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报