Thanks to visit codestin.com
Credit goes to github.com

Skip to content

xuruiray/rayRoute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rayRoute

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

安装

go get github.com/xuruiray/rayRoute

示例

package main

import "github.com/xuruiray/rayRoute"
import "net/http"
import "context"

func main(){
	//创建路由复用器
	mux := rayRoute.CreateNewRemux()

	//添加中间件
	mux.AddMiddleware(testMiddleware)

	//绑定 controller
	mux.SetHandlerMapping("/hello",helloHandler)

	//开始监听并阻塞
	http.ListenAndServe(":8001",mux)
}


//自主编写的Controller
func helloHandler(conntext context.Context, req *http.Request) (string){
	return "hello world\n"
}

//自主编写的middleware
func testMiddleware(next http.HandlerFunc) http.HandlerFunc{
	f := func(w http.ResponseWriter,req *http.Request){
		w.Write([]byte("forward\n"))
		//下一个中间件逻辑
		next.ServeHTTP(w,req)
		w.Write([]byte("backward\n"))
	}
	return http.HandlerFunc(f)
}

Radix Tree

About

简易的 go web框架

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages