项目作者: xuruiray

项目描述 :
简易的 go web框架
高级语言: Go
项目地址: git://github.com/xuruiray/rayRoute.git
创建时间: 2017-07-19T13:56:49Z
项目社区:https://github.com/xuruiray/rayRoute

开源协议:

关键词:
go radix-tree router tree

下载


rayRoute

简易的路由框架,使用了基数树作为路由结构,添加了中间件层

安装

  1. go get github.com/xuruiray/rayRoute

示例

  1. package main
  2. import "github.com/xuruiray/rayRoute"
  3. import "net/http"
  4. import "context"
  5. func main(){
  6. //创建路由复用器
  7. mux := rayRoute.CreateNewRemux()
  8. //添加中间件
  9. mux.AddMiddleware(testMiddleware)
  10. //绑定 controller
  11. mux.SetHandlerMapping("/hello",helloHandler)
  12. //开始监听并阻塞
  13. http.ListenAndServe(":8001",mux)
  14. }
  15. //自主编写的Controller
  16. func helloHandler(conntext context.Context, req *http.Request) (string){
  17. return "hello world\n"
  18. }
  19. //自主编写的middleware
  20. func testMiddleware(next http.HandlerFunc) http.HandlerFunc{
  21. f := func(w http.ResponseWriter,req *http.Request){
  22. w.Write([]byte("forward\n"))
  23. //下一个中间件逻辑
  24. next.ServeHTTP(w,req)
  25. w.Write([]byte("backward\n"))
  26. }
  27. return http.HandlerFunc(f)
  28. }

Radix Tree