我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

如何安装和运行GoAdminGroup/go-admin-创新互联

今天就跟大家聊聊有关如何安装和运行GoAdminGroup/go-admin,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联专注于新野企业网站建设,响应式网站开发,成都做商城网站。新野网站建设公司,为新野等地区提供建站服务。全流程按需求定制网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

使用这个GoAdminGroup/go-admin框架的最简单的例子就可以把项目运行起来 , go-admin 是以扩展库的形式使用的.

建一个main.go

package main

import (
  "io/ioutil"
  "log"
  "os"
  "os/signal"

  _ "github.com/GoAdminGroup/go-admin/adapter/gin"
  _ "github.com/GoAdminGroup/go-admin/modules/db/drivers/mysql"
  _ "github.com/GoAdminGroup/themes/sword"

  "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/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/gin-gonic/gin"
)

func main() {
  gin.SetMode(gin.ReleaseMode)
  gin.DefaultWriter = ioutil.Discard

  r := gin.New()

  e := engine.Default()

  cfg := config.Config{
    Env: config.EnvLocal,
    Databases: config.DatabaseList{
      "default": {
        Host:    "127.0.0.1",
        Port:    "3306",
        User:    "goadmin",
        Pwd:    "goadmin",
        Name:    "goadmin",
        MaxIdleCon: 50,
        MaxOpenCon: 150,
        Driver:   config.DriverMysql,

        //Driver: config.DriverSqlite,
        //File:  "../datamodel/admin.db",
      },
    },
    UrlPrefix: "admin",
    Store: config.Store{
      Path:  "./uploads",
      Prefix: "uploads",
    },
    Language:      language.CN,
    IndexUrl:      "/",
    Debug:       true,
    AccessAssetsLogOff: true,
    Animation: config.PageAnimation{
      Type: "fadeInUp",
    },
    ColorScheme:    adminlte.ColorschemeSkinBlack,
    BootstrapFilePath: "./../datamodel/bootstrap.go",
  }

  template.AddComp(chartjs.NewChart())

  // customize a plugin

  examplePlugin := example.NewExample()

  // load from golang.Plugin
  //
  // examplePlugin := plugins.LoadFromPlugin("../datamodel/example.so")

  // customize the login page
  // example: /tupian/20230522/main.go
  //
  // template.AddComp("login", datamodel.LoginPage)

  // load config from json file
  //
  // e.AddConfigFromJSON("../datamodel/config.json")

  if err := e.AddConfig(cfg).
    AddGenerators(datamodel.Generators).
    // add generator, first parameter is the url prefix of table when visit.
    // example:
    //
    // "user" => http://localhost:9033/admin/info/user
    //
    AddGenerator("user", datamodel.GetUserTable).
    AddDisplayFilterXssJsFilter().
    AddPlugins(examplePlugin).
    Use(r); err != nil {
    panic(err)
  }

  r.Static("/uploads", "./uploads")

  // customize your pages

  e.HTML("GET", "/admin", datamodel.GetContent)

  go func() {
    _ = r.Run(":9033")
  }()

  quit := make(chan os.Signal, 1)
  signal.Notify(quit, os.Interrupt)
  <-quit
  log.Print("closing database connection")
  e.MysqlConnection().Close()
}

网页标题:如何安装和运行GoAdminGroup/go-admin-创新互联
地址分享:http://mswzjz.cn/article/dheddo.html

其他资讯