欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

GoAdminGroup/go-admin的安装和运行的教程详解

程序员文章站 2022-03-27 14:01:39
使用这个goadmingroup/go-admin框架的最简单的例子就可以把项目运行起来 , go-admin 是以扩展库的形式使用的.建一个main.gopackage mainimport (...

使用这个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: https://github.com/goadmingroup/demo.go-admin.cn/blob/master/main.go#l39
  //
  // 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()
}

注意数据库用户名和密码 , 直接运行go run main.go , 在开启go module的情况下 , 所有依赖会自动安装

访问 http://localhost:9033/admin 用户名密码:admin / admin

GoAdminGroup/go-admin的安装和运行的教程详解

建一个数据库 , 把数据库sql导进去

# ************************************************************
# sequel pro sql dump
# version 4468
#
# http://www.sequelpro.com/
# https://github.com/sequelpro/sequelpro
#
# host: 127.0.0.1 (mysql 5.7.19)
# database: godmin
# generation time: 2019-09-12 04:16:47 +0000
# ************************************************************


/*!40101 set @old_character_set_client=@@character_set_client */;
/*!40101 set @old_character_set_results=@@character_set_results */;
/*!40101 set @old_collation_connection=@@collation_connection */;
/*!40101 set names utf8 */;
/*!40014 set @old_foreign_key_checks=@@foreign_key_checks, foreign_key_checks=0 */;
/*!40101 set @old_sql_mode=@@sql_mode, sql_mode='no_auto_value_on_zero' */;
/*!40111 set @old_sql_notes=@@sql_notes, sql_notes=0 */;


# dump of table goadmin_menu
# ------------------------------------------------------------

drop table if exists `goadmin_menu`;

create table `goadmin_menu` (
 `id` int(10) unsigned not null auto_increment,
 `parent_id` int(11) unsigned not null default '0',
 `type` tinyint(4) unsigned not null default '0',
 `order` int(11) unsigned not null default '0',
 `title` varchar(50) collate utf8mb4_unicode_ci not null,
 `icon` varchar(50) collate utf8mb4_unicode_ci not null,
 `uri` varchar(3000) collate utf8mb4_unicode_ci not null default '',
 `header` varchar(150) collate utf8mb4_unicode_ci default null,
 `plugin_name` varchar(150) collate utf8mb4_unicode_ci not null default '',
 `uuid` varchar(150) collate utf8mb4_unicode_ci default null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_menu` write;
/*!40000 alter table `goadmin_menu` disable keys */;

insert into `goadmin_menu` (`id`, `parent_id`, `type`, `order`, `title`, `icon`, `uri`, `plugin_name`, `header`, `created_at`, `updated_at`)
values
  (1,0,1,2,'admin','fa-tasks','','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,1,1,2,'users','fa-users','/info/manager','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (3,1,1,3,'roles','fa-user','/info/roles','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (4,1,1,4,'permission','fa-ban','/info/permission','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (5,1,1,5,'menu','fa-bars','/menu','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (6,1,1,6,'operation log','fa-history','/info/op','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (7,0,1,1,'dashboard','fa-bar-chart','/','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_menu` enable keys */;
unlock tables;


# dump of table goadmin_operation_log
# ------------------------------------------------------------

drop table if exists `goadmin_operation_log`;

create table `goadmin_operation_log` (
 `id` int(10) unsigned not null auto_increment,
 `user_id` int(11) unsigned not null,
 `path` varchar(255) collate utf8mb4_unicode_ci not null,
 `method` varchar(10) collate utf8mb4_unicode_ci not null,
 `ip` varchar(15) collate utf8mb4_unicode_ci not null,
 `input` text collate utf8mb4_unicode_ci not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`),
 key `admin_operation_log_user_id_index` (`user_id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;


# dump of table goadmin_site
# ------------------------------------------------------------

drop table if exists `goadmin_site`;

create table `goadmin_site` (
 `id` int(11) unsigned not null auto_increment,
 `key` varchar(100) collate utf8mb4_unicode_ci default null,
 `value` longtext collate utf8mb4_unicode_ci,
 `description` varchar(3000) collate utf8mb4_unicode_ci default null,
 `state` tinyint(3) unsigned not null default '0',
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;


# dump of table goadmin_permissions
# ------------------------------------------------------------

drop table if exists `goadmin_permissions`;

create table `goadmin_permissions` (
 `id` int(10) unsigned not null auto_increment,
 `name` varchar(50) collate utf8mb4_unicode_ci not null,
 `slug` varchar(50) collate utf8mb4_unicode_ci not null,
 `http_method` varchar(255) collate utf8mb4_unicode_ci default null,
 `http_path` text collate utf8mb4_unicode_ci not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`),
 unique key `admin_permissions_name_unique` (`name`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_permissions` write;
/*!40000 alter table `goadmin_permissions` disable keys */;

insert into `goadmin_permissions` (`id`, `name`, `slug`, `http_method`, `http_path`, `created_at`, `updated_at`)
values
  (1,'all permission','*','','*','2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,'dashboard','dashboard','get,put,post,delete','/','2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_permissions` enable keys */;
unlock tables;


# dump of table goadmin_role_menu
# ------------------------------------------------------------

drop table if exists `goadmin_role_menu`;

create table `goadmin_role_menu` (
 `role_id` int(11) unsigned not null,
 `menu_id` int(11) unsigned not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 key `admin_role_menu_role_id_menu_id_index` (`role_id`,`menu_id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_role_menu` write;
/*!40000 alter table `goadmin_role_menu` disable keys */;

insert into `goadmin_role_menu` (`role_id`, `menu_id`, `created_at`, `updated_at`)
values
  (1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (1,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (1,8,'2019-09-11 10:20:55','2019-09-11 10:20:55'),
  (2,8,'2019-09-11 10:20:55','2019-09-11 10:20:55');

/*!40000 alter table `goadmin_role_menu` enable keys */;
unlock tables;


# dump of table goadmin_role_permissions
# ------------------------------------------------------------

drop table if exists `goadmin_role_permissions`;

create table `goadmin_role_permissions` (
 `role_id` int(11) unsigned not null,
 `permission_id` int(11) unsigned not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 unique key `admin_role_permissions` (`role_id`,`permission_id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_role_permissions` write;
/*!40000 alter table `goadmin_role_permissions` disable keys */;

insert into `goadmin_role_permissions` (`role_id`, `permission_id`, `created_at`, `updated_at`)
values
  (1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (1,2,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,2,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_role_permissions` enable keys */;
unlock tables;


# dump of table goadmin_role_users
# ------------------------------------------------------------

drop table if exists `goadmin_role_users`;

create table `goadmin_role_users` (
 `role_id` int(11) unsigned not null,
 `user_id` int(11) unsigned not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 unique key `admin_user_roles` (`role_id`,`user_id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_role_users` write;
/*!40000 alter table `goadmin_role_users` disable keys */;

insert into `goadmin_role_users` (`role_id`, `user_id`, `created_at`, `updated_at`)
values
  (1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,2,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_role_users` enable keys */;
unlock tables;


# dump of table goadmin_roles
# ------------------------------------------------------------

drop table if exists `goadmin_roles`;

create table `goadmin_roles` (
 `id` int(10) unsigned not null auto_increment,
 `name` varchar(50) collate utf8mb4_unicode_ci not null,
 `slug` varchar(50) collate utf8mb4_unicode_ci not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`),
 unique key `admin_roles_name_unique` (`name`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_roles` write;
/*!40000 alter table `goadmin_roles` disable keys */;

insert into `goadmin_roles` (`id`, `name`, `slug`, `created_at`, `updated_at`)
values
  (1,'administrator','administrator','2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,'operator','operator','2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_roles` enable keys */;
unlock tables;


# dump of table goadmin_session
# ------------------------------------------------------------

drop table if exists `goadmin_session`;

create table `goadmin_session` (
 `id` int(11) unsigned not null auto_increment,
 `sid` varchar(50) character set utf8mb4 collate utf8mb4_unicode_ci not null default '',
 `values` varchar(3000) character set utf8mb4 collate utf8mb4_unicode_ci not null default '',
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`)
) engine=innodb default charset=utf8mb4;



# dump of table goadmin_user_permissions
# ------------------------------------------------------------

drop table if exists `goadmin_user_permissions`;

create table `goadmin_user_permissions` (
 `user_id` int(11) unsigned not null,
 `permission_id` int(11) unsigned not null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 unique key `admin_user_permissions` (`user_id`,`permission_id`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_user_permissions` write;
/*!40000 alter table `goadmin_user_permissions` disable keys */;

insert into `goadmin_user_permissions` (`user_id`, `permission_id`, `created_at`, `updated_at`)
values
  (1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,2,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_user_permissions` enable keys */;
unlock tables;


# dump of table goadmin_users
# ------------------------------------------------------------

drop table if exists `goadmin_users`;

create table `goadmin_users` (
 `id` int(10) unsigned not null auto_increment,
 `username` varchar(100) collate utf8mb4_unicode_ci not null,
 `password` varchar(100) collate utf8mb4_unicode_ci not null default '',
 `name` varchar(100) collate utf8mb4_unicode_ci not null,
 `avatar` varchar(255) collate utf8mb4_unicode_ci default null,
 `remember_token` varchar(100) collate utf8mb4_unicode_ci default null,
 `created_at` timestamp null default current_timestamp,
 `updated_at` timestamp null default current_timestamp,
 primary key (`id`),
 unique key `admin_users_username_unique` (`username`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_unicode_ci;

lock tables `goadmin_users` write;
/*!40000 alter table `goadmin_users` disable keys */;

insert into `goadmin_users` (`id`, `username`, `password`, `name`, `avatar`, `remember_token`, `created_at`, `updated_at`)
values
  (1,'admin','$2a$10$u3f/nsaf2kavbyxtbp7ppon0jzfyrqxrnyxb.amiocjxl3ciaj4oy','admin','','tlncbvk9avfyh7wenwb1rkvocju8ffry4um3djtwdhujy0dwfslogac0xufh','2019-09-10 00:00:00','2019-09-10 00:00:00'),
  (2,'operator','$2a$10$rvqkozhjn2mdleprrflb1egp0ozxusrbjlomjagfscd81yzm0bsh.','operator','',null,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 alter table `goadmin_users` enable keys */;
unlock tables;



/*!40111 set sql_notes=@old_sql_notes */;
/*!40101 set sql_mode=@old_sql_mode */;
/*!40014 set foreign_key_checks=@old_foreign_key_checks */;
/*!40101 set character_set_client=@old_character_set_client */;
/*!40101 set character_set_results=@old_character_set_results */;
/*!40101 set collation_connection=@old_collation_connection */;

总结

到此这篇关于goadmingroup/go-admin的安装和运行的教程详解的文章就介绍到这了,更多相关go-admin 安装和运行内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!