HTTP 请求路由:HttpRouter

jopen 10年前

HttpRouter 是一个 Go 语言开发的轻量级高性能 HTTP 请求路由,也可以叫多路复用。

示例代码:

package main     import (      "fmt"      "github.com/julienschmidt/httprouter"      "net/http"      "log"  )     func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {      fmt.Fprint(w, "Welcome!\n")  }     func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {      fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))  }     func main() {      router := httprouter.New()      router.GET("/", Index)      router.GET("/hello/:name", Hello)         log.Fatal(http.ListenAndServe(":8080", router))  }

项目主页:http://www.open-open.com/lib/view/home/1431652971326