Skip to content

Commit

Permalink
Fix: example custom page url
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Sep 12, 2019
1 parent e4e7c21 commit 715e3a0
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/cn/instruction/pages/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {

// 这样子去自定义一个页面:

r.GET(cfg.Url("/custom"), func(ctx *gin.Context) {
r.GET("/admin/custom", func(ctx *gin.Context) {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
2 changes: 1 addition & 1 deletion docs/en/instruction/pages/pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
r.Static("/uploads", "./uploads")

// custom page endpoint
r.GET(cfg.Url("/custom"), func(ctx *gin.Context) {
r.GET("/admin/custom", func(ctx *gin.Context) {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
2 changes: 1 addition & 1 deletion examples/beego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {

// you can custom your pages like:

app.Handlers.Get(cfg.Url("/custom"), func(ctx *context.Context) {
app.Handlers.Get("/admin/custom", func(ctx *context.Context) {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
2 changes: 1 addition & 1 deletion examples/buffalo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {

// you can custom your pages like:

bu.GET(cfg.Url("/custom"), func(ctx buffalo.Context) error {
bu.GET("/admin/custom", func(ctx buffalo.Context) error {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
2 changes: 1 addition & 1 deletion examples/fasthttp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
panic(err)
}

router.GET(cfg.Url("/custom"), func(ctx *fasthttp.RequestCtx) {
router.GET("/admin/custom", func(ctx *fasthttp.RequestCtx) {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
5 changes: 3 additions & 2 deletions examples/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ func main() {
//
// "user" => http://localhost:9033/admin/info/user
//
adminPlugin.AddGenerator("user", datamodel.GetUserTable)
//adminPlugin.AddGenerator("user", datamodel.GetUserTable)

// customize a plugin

examplePlugin := example.NewExample()
//examplePlugin := plugins.LoadFromPlugin("./plugin.so")

// customize the login page
// template.AddComp("login", datamodel.LoginPage)
Expand All @@ -77,7 +78,7 @@ func main() {

// customize your pages

r.GET(cfg.Url("/custom"), func(ctx *gin.Context) {
r.GET("/admin/custom", func(ctx *gin.Context) {
engine.Content(ctx, func() types.Panel {
return datamodel.GetContent()
})
Expand Down
2 changes: 1 addition & 1 deletion modules/language/language_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import "testing"

func TestAdd(t *testing.T) {
Add("cn", map[string]string{})
}
}
4 changes: 4 additions & 0 deletions plugins/example/go_plugin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all: build

build:
go build -buildmode=plugin -o plugin.so main.go
8 changes: 8 additions & 0 deletions plugins/example/go_plugin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import (
"github.com/chenhg5/go-admin/plugins"
"github.com/chenhg5/go-admin/plugins/example"
)

var Plugin plugins.Plugin = example.NewExample()
29 changes: 29 additions & 0 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
package plugins

import (
"fmt"
"github.com/chenhg5/go-admin/context"
"os"
"plugin"
"reflect"
)

// Plugin as one of the key components of goAdmin has three
Expand All @@ -31,3 +35,28 @@ func GetHandler(url, method string, app *context.App) context.Handlers {

return handler
}

func LoadFromPlugin(mod string) Plugin {

plug, err := plugin.Open(mod)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

symPlugin, err := plug.Lookup("Plugin")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(reflect.TypeOf(symPlugin))

var p Plugin
p, ok := symPlugin.(Plugin)
if !ok {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}

return p
}
Loading

0 comments on commit 715e3a0

Please sign in to comment.