https://github.com/fudali113/doob
simple & powerful golang restful micro-framework
https://github.com/fudali113/doob
api go micro-framework rest web
Last synced: 5 months ago
JSON representation
simple & powerful golang restful micro-framework
- Host: GitHub
- URL: https://github.com/fudali113/doob
- Owner: fudali113
- License: apache-2.0
- Created: 2016-08-06T13:03:25.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-10T13:40:30.000Z (about 9 years ago)
- Last Synced: 2024-06-20T10:11:50.725Z (about 2 years ago)
- Topics: api, go, micro-framework, rest, web
- Language: Go
- Homepage: http://blog.fudali.cc/doob
- Size: 3.36 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Doob

Doob is a rest and a simple router handler
init invoke AddHandlerFunc(forwardUrl,methodStr,func)
such as
* add static folder
```
Doob.AddStaicPrefix("/static")
```
* add forwardUrl func , use `&&` split urls
```
router := Doob.DefaultRouter()
router.AddHandlerFunc("/Doob/origin/{who}/{do} && /Doob/origin1/{who}/{do}", origin, Doob.GET, Doob.POST, Doob.PUT, Doob.DELETE)
```
* use `Get,Post,Put,Delete,Options,Head` method
```
// get '/Doob' at the beginning base router
doobPrefixRouter := Doob.GetRouter("Doob")
// use `{}` distinction pathVariable
doobPrefixRouter.Get("/{name}/{value}", func)
// {} 中支持添加正则表达式,用`:`分割参数名和正则表达式
doobPrefixRouter.Post("/{name:[0-9]+}/{value}", func)
doobPrefixRouter.Put("/{name}/{value}", func)
doobPrefixRouter.Delete("/{name}/{value}", func)
doobPrefixRouter.Options("/{name}/{value}", func)
doobPrefixRouter.Head("/{name}/{value}", func)
```
* if your not has HEAD or OPTIONS method , doob is add default HEAD and OPTIOND method
```
HEAD is return this url get method headers
OPTIONS is return this url support methods
```
* support func classify
```
// 兼容原始http方法类
func origin(w http.ResponseWriter, r *http.Request) {}
// 根据doob 里的context 进行获取参数或者返回
func ctx(ctx *Doob.Context) interface{} {}
// 根据url参数自动注入参数
// 返回值为string时为返回静态文件
// 返回不为string时默认将解析该对象,并返回给请求用户
func di(name, value string) interface{} {}
// 返回 string 是 type, interface{} 是你需要处理的数据
// 你的返回值将流向注册的返回值处理器进行匹配并处理
// 当只返回string时,把interface当做nil
//
// 当只返回数据时,此时returnDealDefaultType 为 auto
// 此时将根据 請求的header Accept参数进行判断type类型
// 你可以通过SetReturnDealDefaultType(t string)设置默认的type类型
func returnHtml() (string, interface{}) {}
```
* next use
```
Doob.Start(8888)
```
run you application
clone this project , run demo
```
cd /sample
go run demo.go
```