Skip to content

Commit ef7dcfd

Browse files
author
cg33
committed
feat(plugins): improve plugins && ready for v1.2.15
1 parent 4263d47 commit ef7dcfd

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GOCMD = go
22
GOBUILD = $(GOCMD) build
33
BINARY_NAME = adm
4-
LAST_VERSION = v1.2.13
5-
VERSION = v1.2.14
4+
LAST_VERSION = v1.2.14
5+
VERSION = v1.2.15
66
CLI = adm
77

88
TEST_CONFIG_PATH=./../../common/config.json

adm/plugin_template.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ type {{.PluginTitle}} struct {
2929
3030
func init() {
3131
plugins.Add(&{{.PluginTitle}}{
32-
Base: &plugins.Base{PlugName: "{{.PluginName}}"},
32+
Base: &plugins.Base{PlugName: "{{.PluginName}}", URLPrefix: "{{.PluginName}}"},
3333
// ....
3434
})
3535
}
3636
3737
func New{{.PluginTitle}}(/*...*/) *{{.PluginTitle}} {
3838
return &{{.PluginTitle}}{
39-
Base: &plugins.Base{PlugName: "{{.PluginName}}"},
39+
Base: &plugins.Base{PlugName: "{{.PluginName}}", URLPrefix: "{{.PluginName}}"},
4040
// ...
4141
}
4242
}
4343
4444
func (plug *{{.PluginTitle}}) IsInstalled() bool {
45-
panic("implement it")
45+
// ... implement it
46+
return true
47+
}
48+
49+
func (plug *{{.PluginTitle}}) GetIndexURL() string {
50+
return config.Url("/{{.PluginName}}/example?param=helloworld")
4651
}
4752
4853
func (plug *{{.PluginTitle}}) InitPlugin(srv service.List) {
4954
5055
// DO NOT DELETE
51-
plug.InitBase(srv)
56+
plug.InitBase(srv, "{{.PluginName}}")
5257
5358
plug.handler = controller.NewHandler(/*...*/)
5459
plug.guard = guard.New(/*...*/)
@@ -59,7 +64,7 @@ func (plug *{{.PluginTitle}}) InitPlugin(srv service.List) {
5964
language.Lang[language.CN].Combine(language2.CN)
6065
language.Lang[language.EN].Combine(language2.EN)
6166
62-
f.SetInfo(info)
67+
plug.SetInfo(info)
6368
}
6469
6570
var info = plugins.Info{
@@ -120,8 +125,8 @@ func (plug *{{.PluginTitle}}) GetSettingPage() table.Generator {
120125
121126
import (
122127
"github.com/GoAdminGroup/go-admin/context"
123-
"github.com/GoAdminGroup/go-admin/plugins"
124128
"github.com/GoAdminGroup/go-admin/template"
129+
"github.com/GoAdminGroup/go-admin/template/types"
125130
)
126131
127132
type Handler struct {
@@ -187,7 +192,7 @@ type ExampleParam struct {
187192
188193
func (g *Guardian) Example(ctx *context.Context) {
189194
190-
param := ctx.FormValue("param")
195+
param := ctx.Query("param")
191196
192197
ctx.SetUserValue("example", &ExampleParam{
193198
Param: param,
@@ -212,17 +217,15 @@ test:
212217
import (
213218
"github.com/GoAdminGroup/go-admin/context"
214219
"github.com/GoAdminGroup/go-admin/modules/auth"
215-
"github.com/GoAdminGroup/go-admin/modules/config"
216220
"github.com/GoAdminGroup/go-admin/modules/service"
217221
)
218222
219223
func (plug *{{.PluginTitle}}) initRouter(srv service.List) *context.App {
220224
221225
app := context.NewApp()
222-
route := app.Group(config.GetUrlPrefix())
223-
authRoute := route.Group("/", auth.Middleware(plug.Conn))
226+
authRoute := app.Group("/", auth.Middleware(plug.Conn))
224227
225-
authRoute.POST("/{{.PluginName}}/example", plug.guard.Example, plug.handler.Example)
228+
authRoute.GET("/example", plug.guard.Example, plug.handler.Example)
226229
227230
return app
228231
}`,

plugins/admin/controller/plugins.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,16 @@ func (h *Handler) PluginDownload(ctx *context.Context) {
465465
}
466466

467467
if h.config.BootstrapFilePath != "" && utils.FileExist(h.config.BootstrapFilePath) {
468-
content, _ := ioutil.ReadFile(h.config.BootstrapFilePath)
469-
_ = ioutil.WriteFile(h.config.BootstrapFilePath, []byte(string(content)+`
468+
content, err := ioutil.ReadFile(h.config.BootstrapFilePath)
469+
if err != nil {
470+
logger.Error("read bootstrap file error: ", err)
471+
} else {
472+
err = ioutil.WriteFile(h.config.BootstrapFilePath, []byte(string(content)+`
470473
import _ "`+plug.GetInfo().ModulePath+`"`), 0644)
474+
if err != nil {
475+
logger.Error("write bootstrap file error: ", err)
476+
}
477+
}
471478
}
472479

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

0 commit comments

Comments
 (0)