Skip to content

Commit 8173ff6

Browse files
author
pixel
committed
插件功能开发完整度 +1
1 parent c4a6b33 commit 8173ff6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

server/core/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"gin-vue-admin/global"
66
"gin-vue-admin/initialize"
7+
"github.com/piexlmax/gvaplug"
78
"net/http"
89
"time"
910
)
@@ -15,6 +16,11 @@ func RunWindowsServer() {
1516
}
1617
Router := initialize.Routers()
1718
Router.Static("/form-generator", "./resource/page")
19+
err := initialize.InstallPlug(global.GVA_DB, Router, gvaplug.GvaPlug{})
20+
if err != nil {
21+
panic(fmt.Sprintf("插件安装失败: %v", err))
22+
}
23+
1824
address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr)
1925
s := &http.Server{
2026
Addr: address,

server/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1111
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
1212
github.com/fsnotify/fsnotify v1.4.9
13-
github.com/gin-gonic/gin v1.6.1
13+
github.com/gin-gonic/gin v1.6.3
1414
github.com/go-openapi/spec v0.19.7 // indirect
1515
github.com/go-openapi/swag v0.19.8 // indirect
1616
github.com/go-redis/redis v6.15.7+incompatible
@@ -28,6 +28,7 @@ require (
2828
github.com/onsi/gomega v1.4.3 // indirect
2929
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
3030
github.com/pelletier/go-toml v1.6.0 // indirect
31+
github.com/piexlmax/gvaplug v0.0.5
3132
github.com/pkg/errors v0.9.1 // indirect
3233
github.com/qiniu/api.v7 v7.2.5+incompatible
3334
github.com/qiniu/x v7.0.8+incompatible // indirect

server/initialize/plug.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package initialize
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/jinzhu/gorm"
6+
)
7+
8+
type Plug interface {
9+
InitRouter(*gin.Engine) error
10+
InitModel(*gorm.DB) error
11+
}
12+
13+
func InstallPlug(db *gorm.DB, router *gin.Engine, p ...Plug) (err error) {
14+
for _, v := range p {
15+
err = v.InitModel(db)
16+
if err != nil {
17+
return err
18+
}
19+
err = v.InitRouter(router)
20+
if err != nil {
21+
return err
22+
}
23+
}
24+
return nil
25+
}

0 commit comments

Comments
 (0)