关于Martini web framework 后续

Martini 是一个Go语言的早期Web框架,它从Ruby 的Web框架当中吸收了很多思想(比如依赖注入)。最初,这个框架在社区中引起了强烈的反响,但是它逐渐在性能和可调试性上受到了一些批评。Martini 框架的作者Jeremy Saenz 积极响应这些来自Go社区的反馈,写了一个更加符合Go语言规范的库Negroni

Martini https://github.com/go-martini/martini 2 Negroni https://github.com/codegangsta/negroni

negroni 例子

package main

import (
  "github.com/codegangsta/negroni"
  "net/http"
  "fmt"
)

func main() {
  mux := http.NewServeMux()
  mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    fmt.Fprintf(w, "Welcome to the home page!")
  })

  n := negroni.Classic()
  n.UseHandler(mux)
  n.Run(":3000")
}

但速度仍不及goji https://github.com/zenazn/goji 1

同样hello world

[negroni] Started GET /
[negroni] Completed 200 OK in 116.479µs

goji
2015/06/07 10:25:41.551511 [xxx/JO4kbhB73C-000005] Started GET "/" from 127.0.0.1:37318
2015/06/07 10:25:41.551632 [xxx/JO4kbhB73C-000005] Returning 200 in 26.425µs

Relative Articles