Plugins Development
A plugin needs to implement the corresponding four interfaces, such as:
1
// Plug-in is an important part of GoAdmin. Different plug-ins have different features.
2
type Plugin interface {
3
4
// Get handlers
5
GetHandler() context.HandlerMap
6
7
// Initialize the plug-in
8
InitPlugin(services service.List)
9
10
// Get plugin name
11
Name() string
12
13
// Url prefix
14
Prefix() string
15
}
Copied!
Create a new plug-in must inheritplugin.Base. For example:
1
package example
2
3
import (
4
c "github.com/GoAdminGroup/go-admin/modules/config"
5
"github.com/GoAdminGroup/go-admin/modules/service"
6
"github.com/GoAdminGroup/go-admin/plugins"
7
)
8
9
type Example struct {
10
*plugins.Base
11
}
12
13
func NewExample() *Example {
14
return &Example{
15
Base: &plugins.Base{PlugName: "example", URLPrefix: "example"},
16
}
17
}
18
19
func (e *Example) InitPlugin(srv service.List) {
20
e.InitBase(srv)
21
e.App = e.initRouter(c.Prefix(), srv)
22
}
23
24
func (e *Example) initRouter(prefix, srv service.List) {
25
26
app := context.NewApp()
27
route := app.Group(prefix)
28
// Join the certification middleware
29
route.GET("/show/me/something", auth.Middleware(db.GetConnection(srv)), func(ctx *context.Context){
30
// Controller logic
31
})
32
return app
33
}
Copied!
More:
Last modified 1yr ago
Copy link