cedar-router 介绍
cedar,轻量级 Golang 路由器,基于前缀树算法。
cedar.NewRouter().Get(prefix,http.HandlerFunc,http.Handler)
全局方法
r.GlobalFunc("test", func(r *http.Request) error { fmt.Println("123213") return nil })
支持常见的method
r := cedar.NewRouter() r.Get("/",http.HandlerFunc(),nil) r.Post("/",http.HandlerFunc(),nil) r.Put("/",http.HandlerFunc(),nil) r.Delete("/",http.HandlerFunc(),nil)
handFunc和Handler在同一路径下我建议只填写一个 . 测试通过websocket
,静态文件路由需要改写ServerHTTP方法.我默认在当前路径下 static/
同一路由下 不同Method ,会覆盖前面的的HandlerFunc和Handler
群组路由
r := cedar.NewRouter() r.Group("/a",func (group *cedar.Groups){ group.Get("/b",http.HandlerFunc(),nil) group.Group("/c",func(groups *cedar.Groups) { group.Get("/d",http.HandlerFunc(),nil) }) })
同时也支持RestFul风格
r := cedar.NewRestRouter(cedar.RestConfig{ EntryPath: "blog", ApiName: "api", Pattern: ".", }) r.Get("user", func(writer http.ResponseWriter, request *http.Request) { r.Template(writer, "/index") }, nil) //localhost/blog?api=user
通过 localhost/blog?api=user 获得访问.
软件稳定运行在服务器
cedar-router 官网
https://yaop.ink/software/cedar
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。