Browse Source

插件功能开发完整度 +1

main
pixel 4 years ago
parent
commit
24a0e49a57
  1. 6
      server/core/server.go
  2. 3
      server/go.mod
  3. 25
      server/initialize/plug.go

6
server/core/server.go

@ -4,6 +4,7 @@ import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/initialize"
"github.com/piexlmax/gvaplug"
"net/http"
"time"
)
@ -15,6 +16,11 @@ func RunWindowsServer() {
}
Router := initialize.Routers()
Router.Static("/form-generator", "./resource/page")
err := initialize.InstallPlug(global.GVA_DB, Router, gvaplug.GvaPlug{})
if err != nil {
panic(fmt.Sprintf("插件安装失败: %v", err))
}
address := fmt.Sprintf(":%d", global.GVA_CONFIG.System.Addr)
s := &http.Server{
Addr: address,

3
server/go.mod

@ -10,7 +10,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.6.1
github.com/gin-gonic/gin v1.6.3
github.com/go-openapi/spec v0.19.7 // indirect
github.com/go-openapi/swag v0.19.8 // indirect
github.com/go-redis/redis v6.15.7+incompatible
@ -28,6 +28,7 @@ require (
github.com/onsi/gomega v1.4.3 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/piexlmax/gvaplug v0.0.5
github.com/pkg/errors v0.9.1 // indirect
github.com/qiniu/api.v7 v7.2.5+incompatible
github.com/qiniu/x v7.0.8+incompatible // indirect

25
server/initialize/plug.go

@ -0,0 +1,25 @@
package initialize
import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
)
type Plug interface {
InitRouter(*gin.Engine) error
InitModel(*gorm.DB) error
}
func InstallPlug(db *gorm.DB, router *gin.Engine, p ...Plug) (err error) {
for _, v := range p {
err = v.InitModel(db)
if err != nil {
return err
}
err = v.InitRouter(router)
if err != nil {
return err
}
}
return nil
}
Loading…
Cancel
Save