How To Use Plugins
The framework's plugins include: controllers, routing, and views. The specific plug-in development will be discussed in the project development part, here just show you how to use it.
The example plugin is our demo.
Using plugins are divided into: using the third package source code plugin and use the dynamic link library plugin (.so file, currently only supports linux and mac platforms)
You can skip this part, if you just want to build a crud administrative platform.

Using the third package source code plugin

For example:
1
package main
2
3
import (
4
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // Import the adapter
5
_ "github.com/GoAdminGroup/themes/adminlte" // Import the theme
6
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql" // Import the sql driver
7
8
"github.com/gin-gonic/gin"
9
"github.com/GoAdminGroup/go-admin/engine"
10
"github.com/GoAdminGroup/go-admin/plugins/admin"
11
"github.com/GoAdminGroup/go-admin/plugins/example"
12
"github.com/GoAdminGroup/go-admin/modules/config"
13
"github.com/GoAdminGroup/go-admin/examples/datamodel"
14
)
15
16
func main() {
17
r := gin.Default()
18
eng := engine.Default()
19
cfg := config.Config{}
20
21
adminPlugin := admin.NewAdmin(datamodel.Generators)
22
examplePlugin := example.NewExample()
23
24
eng.AddConfig(cfg).
25
AddPlugins(adminPlugin, examplePlugin). // loading
26
Use(r)
27
28
r.Run(":9033")
29
}
Copied!

Using the binary plugin

Load the .sofile, and callplugins.LoadFromPlugin.
如:
1
package main
2
3
import (
4
_ "github.com/GoAdminGroup/go-admin/adapter/gin" // Import the adapter
5
_ "github.com/GoAdminGroup/themes/adminlte" // Import the theme
6
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql" // Import the sql driver
7
8
"github.com/gin-gonic/gin"
9
"github.com/GoAdminGroup/go-admin/engine"
10
"github.com/GoAdminGroup/go-admin/plugins/admin"
11
"github.com/GoAdminGroup/go-admin/plugins"
12
"github.com/GoAdminGroup/go-admin/modules/config"
13
"github.com/GoAdminGroup/go-admin/examples/datamodel"
14
)
15
16
func main() {
17
r := gin.Default()
18
eng := engine.Default()
19
cfg := config.Config{}
20
21
adminPlugin := admin.NewAdmin(datamodel.Generators)
22
23
// load plugin from .so file.
24
examplePlugin := plugins.LoadFromPlugin("../datamodel/example.so")
25
26
eng.AddConfig(cfg).
27
AddPlugins(adminPlugin, examplePlugin).
28
Use(r)
29
30
r.Run(":9033")
31
}
Copied!
Last modified 1yr ago