-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
49 lines (39 loc) · 968 Bytes
/
init.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
package mano
import (
"container/list"
"sync"
"github.com/junhwong/mano/utils"
)
//The Application interface is ...
// type Application interface {
// }
var defaultApp *Application
func init() {
defaultApp = New()
//defaultApp.Use(RouteHandler)
}
//New returns a new Application.
func New() *Application {
return &Application{
muLock: new(sync.Mutex),
isDefault: true,
attrs: make(utils.Attribute),
handlers: make([]HTTPHandler, 0),
paramterMap: make(map[string]ServiceFunc),
routeTable: &RouteTable{
routes: list.New(),
},
}
}
//Default returns a default(global) Engine instance.
func Default() *Application {
return defaultApp
}
//AddMiddleware method add a Middleware to Application.
func (app *Application) AddMiddleware(name string, ware Middleware, global ...bool) {
if global != nil && len(global) >= 1 && global[0] == true {
app.globalMiddlewares[name] = ware
} else {
app.middlewares[name] = ware
}
}