Skip to content

Commit

Permalink
feat(plugins): improve plugins && ready for v1.2.15
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Aug 4, 2020
1 parent 4263d47 commit ef7dcfd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GOCMD = go
GOBUILD = $(GOCMD) build
BINARY_NAME = adm
LAST_VERSION = v1.2.13
VERSION = v1.2.14
LAST_VERSION = v1.2.14
VERSION = v1.2.15
CLI = adm

TEST_CONFIG_PATH=./../../common/config.json
Expand Down
25 changes: 14 additions & 11 deletions adm/plugin_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,31 @@ type {{.PluginTitle}} struct {
func init() {
plugins.Add(&{{.PluginTitle}}{
Base: &plugins.Base{PlugName: "{{.PluginName}}"},
Base: &plugins.Base{PlugName: "{{.PluginName}}", URLPrefix: "{{.PluginName}}"},
// ....
})
}
func New{{.PluginTitle}}(/*...*/) *{{.PluginTitle}} {
return &{{.PluginTitle}}{
Base: &plugins.Base{PlugName: "{{.PluginName}}"},
Base: &plugins.Base{PlugName: "{{.PluginName}}", URLPrefix: "{{.PluginName}}"},
// ...
}
}
func (plug *{{.PluginTitle}}) IsInstalled() bool {
panic("implement it")
// ... implement it
return true
}
func (plug *{{.PluginTitle}}) GetIndexURL() string {
return config.Url("/{{.PluginName}}/example?param=helloworld")
}
func (plug *{{.PluginTitle}}) InitPlugin(srv service.List) {
// DO NOT DELETE
plug.InitBase(srv)
plug.InitBase(srv, "{{.PluginName}}")
plug.handler = controller.NewHandler(/*...*/)
plug.guard = guard.New(/*...*/)
Expand All @@ -59,7 +64,7 @@ func (plug *{{.PluginTitle}}) InitPlugin(srv service.List) {
language.Lang[language.CN].Combine(language2.CN)
language.Lang[language.EN].Combine(language2.EN)
f.SetInfo(info)
plug.SetInfo(info)
}
var info = plugins.Info{
Expand Down Expand Up @@ -120,8 +125,8 @@ func (plug *{{.PluginTitle}}) GetSettingPage() table.Generator {
import (
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/plugins"
"github.com/GoAdminGroup/go-admin/template"
"github.com/GoAdminGroup/go-admin/template/types"
)
type Handler struct {
Expand Down Expand Up @@ -187,7 +192,7 @@ type ExampleParam struct {
func (g *Guardian) Example(ctx *context.Context) {
param := ctx.FormValue("param")
param := ctx.Query("param")
ctx.SetUserValue("example", &ExampleParam{
Param: param,
Expand All @@ -212,17 +217,15 @@ test:
import (
"github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/modules/auth"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/service"
)
func (plug *{{.PluginTitle}}) initRouter(srv service.List) *context.App {
app := context.NewApp()
route := app.Group(config.GetUrlPrefix())
authRoute := route.Group("/", auth.Middleware(plug.Conn))
authRoute := app.Group("/", auth.Middleware(plug.Conn))
authRoute.POST("/{{.PluginName}}/example", plug.guard.Example, plug.handler.Example)
authRoute.GET("/example", plug.guard.Example, plug.handler.Example)
return app
}`,
Expand Down
11 changes: 9 additions & 2 deletions plugins/admin/controller/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,16 @@ func (h *Handler) PluginDownload(ctx *context.Context) {
}

if h.config.BootstrapFilePath != "" && utils.FileExist(h.config.BootstrapFilePath) {
content, _ := ioutil.ReadFile(h.config.BootstrapFilePath)
_ = ioutil.WriteFile(h.config.BootstrapFilePath, []byte(string(content)+`
content, err := ioutil.ReadFile(h.config.BootstrapFilePath)
if err != nil {
logger.Error("read bootstrap file error: ", err)
} else {
err = ioutil.WriteFile(h.config.BootstrapFilePath, []byte(string(content)+`
import _ "`+plug.GetInfo().ModulePath+`"`), 0644)
if err != nil {
logger.Error("write bootstrap file error: ", err)
}
}
}

if h.config.GoModFilePath != "" && utils.FileExist(h.config.GoModFilePath) &&
Expand Down

0 comments on commit ef7dcfd

Please sign in to comment.