新增admin
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
_ "github.com/GoAdminGroup/go-admin/adapter/iris"
|
||||
"github.com/GoAdminGroup/go-admin/engine"
|
||||
"github.com/GoAdminGroup/go-admin/examples/datamodel"
|
||||
"github.com/GoAdminGroup/go-admin/modules/config"
|
||||
_ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
|
||||
"github.com/GoAdminGroup/go-admin/modules/language"
|
||||
"github.com/GoAdminGroup/go-admin/plugins/example"
|
||||
"github.com/GoAdminGroup/go-admin/template"
|
||||
"github.com/GoAdminGroup/go-admin/template/chartjs"
|
||||
_ "github.com/GoAdminGroup/themes/adminlte"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"go.uber.org/zap"
|
||||
@@ -10,11 +20,13 @@ import (
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Root = "/pet-house"
|
||||
var ExcludeBase = "/static"
|
||||
var ExcludeBase1 = "/debug"
|
||||
var ExcludeBase2 = "/admin"
|
||||
|
||||
var frontExcludes = [...]string{
|
||||
Root + AuthBase + "/login",
|
||||
@@ -38,6 +50,56 @@ func ModuleInit() {
|
||||
DataCacheJob()
|
||||
}
|
||||
|
||||
func GoAdminInit(app *iris.Application) {
|
||||
eng := engine.Default()
|
||||
|
||||
cfg := config.Config{
|
||||
Env: config.EnvLocal,
|
||||
Databases: config.DatabaseList{
|
||||
"default": {
|
||||
Dsn: database.CONFIG.Dsn(),
|
||||
MaxIdleConns: 5,
|
||||
MaxOpenConns: 10,
|
||||
ConnMaxLifetime: time.Hour,
|
||||
Driver: config.DriverMysql,
|
||||
},
|
||||
},
|
||||
Theme: "adminlte",
|
||||
UrlPrefix: Root + "/admin",
|
||||
Store: config.Store{
|
||||
Path: "./static/uploads",
|
||||
Prefix: "/static/uploads",
|
||||
},
|
||||
IndexUrl: Root + "/admin",
|
||||
Debug: true,
|
||||
Language: language.CN,
|
||||
Title: "pet-house",
|
||||
LoginTitle: "pet-house-admin",
|
||||
Logo: "<span class=\"logo-lg\"><b>Pet</b>Admin</span>",
|
||||
}
|
||||
|
||||
template.AddComp(chartjs.NewChart())
|
||||
examplePlugin := example.NewExample()
|
||||
|
||||
if err := eng.AddConfig(&cfg).
|
||||
AddGenerators(datamodel.Generators).
|
||||
AddDisplayFilterXssJsFilter().
|
||||
// add generator, first parameter is the url prefix of table when visit.
|
||||
// example:
|
||||
//
|
||||
// "user" => http://localhost:9033/admin/info/user
|
||||
//
|
||||
AddGenerator("user", datamodel.GetUserTable).
|
||||
AddPlugins(examplePlugin).Use(app); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
app.HandleDir("/static/uploads", "./static/uploads", iris.DirOptions{
|
||||
IndexName: "/index.html",
|
||||
ShowList: false,
|
||||
})
|
||||
eng.HTML("GET", Root+"/admin", datamodel.GetContent)
|
||||
}
|
||||
|
||||
func FrontAuth(ctx *context.Context) {
|
||||
if strings.Contains(ctx.Path(), ExcludeBase) {
|
||||
ctx.Next()
|
||||
@@ -47,6 +109,10 @@ func FrontAuth(ctx *context.Context) {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
if strings.Contains(ctx.Path(), ExcludeBase2) {
|
||||
ctx.Next()
|
||||
return
|
||||
}
|
||||
frontExcludesStr := strings.Join(frontExcludes[:], ",")
|
||||
if strings.Contains(frontExcludesStr, ctx.Path()) {
|
||||
ctx.Next()
|
||||
|
||||
Reference in New Issue
Block a user