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)

Using the third package source code plugin

For example:

package main
import (
"github.com/gin-gonic/gin"
_ "github.com/GoAdminGroup/go-admin/adapter/gin"
_ "github.com/GoAdminGroup/themes/adminlte"
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins/example"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/examples/datamodel"
)
func main() {
r := gin.Default()
eng := engine.Default()
cfg := config.Config{}
adminPlugin := admin.NewAdmin(datamodel.Generators)
examplePlugin := example.NewExample()
eng.AddConfig(cfg).
AddPlugins(adminPlugin, examplePlugin). // loading
Use(r)
r.Run(":9033")
}

Using the binary plugin

Load the .sofile, and callplugins.LoadFromPlugin.

如:

package main
import (
"github.com/gin-gonic/gin"
_ "github.com/GoAdminGroup/go-admin/adapter/gin"
_ "github.com/GoAdminGroup/themes/adminlte" // Import the theme
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/plugins/admin"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/examples/datamodel"
)
func main() {
r := gin.Default()
eng := engine.Default()
cfg := config.Config{}
adminPlugin := admin.NewAdmin(datamodel.Generators)
// load plugin from .so file.
examplePlugin := plugins.LoadFromPlugin("../datamodel/example.so")
eng.AddConfig(cfg).
AddPlugins(adminPlugin, examplePlugin).
Use(r)
r.Run(":9033")
}