-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasicTypes.go
50 lines (36 loc) · 1.22 KB
/
basicTypes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//By yyrdl ,MIT License. Welcome to use and welcome to star it :)
package gbeta
import (
"net/http"
)
type _MiddlewareNode struct {
middleware Middlewares
path string
exsited_max_id int //it means the max node.id that has been added to the router tree
}
type Res interface {
Write([]byte) (int, error)
Header() http.Header
WriteHeader(int)
Code() int
BytesWritten() int64
}
type Req *http.Request
type Middlewares interface {
Do(ctx *Context, w Res, req Req, next Next)
}
//中间件里面使用,next(true)表示继续往下执行,反之表示请求已被中间件返回,可以结束了
type Next func(is_to_next bool)
type ReqHandler func(ctx *Context, res Res, req Req)
type ListenHandler func(err error)
//panic_handler其实没必要,使用者可以通过ServeHTTPWraper实现
//用户自定义panic handler
type PanicHandler func(w Res, req Req, r_c interface{})
//用户自定义NotFound hanler
type NotFoundHandler func(res Res, req Req)
type ServeHTTPFunc func(res Res, req Req)
//内部使用
type ServeHTTPWraper func(ServeHTTPFunc) ServeHTTPFunc
//在context.go里面的checkAndSet方法里面用到
// see the func CheckAndSet in context.go
type CheckFunc func(interface{}, interface{}) bool