forked from GoAdminGroup/go-admin
/
plugins.go
33 lines (26 loc) · 944 Bytes
/
plugins.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
// Copyright 2018 cg33. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package plugins
import (
"github.com/chenhg5/go-admin/context"
)
// Plugin as one of the key components of goAdmin has three
// methods. GetRequest return all the path registered in the
// plugin. GetHandler according the url and method return the
// corresponding handler. InitPlugin init the plugin which do
// something like init the database and set the config and register
// the routes. The Plugin must implement the three methods.
type Plugin interface {
GetRequest() []context.Path
GetHandler(url, method string) context.Handler
InitPlugin()
}
// GetHandler is a help method for Plugin GetHandler.
func GetHandler(url, method string, app *context.App) context.Handler {
handler := app.Find(url, method)
if handler == nil {
panic("handler not found")
}
return handler
}