### Gin-Vue-Admin Quick Start and Setup Source: https://www.gin-vue-admin.com/guide/plugin/develop This section covers the initial steps for getting started with Gin-Vue-Admin, including project introduction, environment configuration, initialization, AI assistant setup, and common issues. ```Markdown ## 快速开始 [环境配置 ](https://www.gin-vue-admin.com/guide/start-quickly/env.html) [初始化 ](https://www.gin-vue-admin.com/guide/start-quickly/initialization.html) [AI助手配置 ](https://www.gin-vue-admin.com/guide/server/mcp.html) [swagger ](https://www.gin-vue-admin.com/guide/start-quickly/swagger.html) [vscode ](https://www.gin-vue-admin.com/guide/start-quickly/vscode.html) [常见问题 ](https://www.gin-vue-admin.com/guide/manual/qa.html) ``` -------------------------------- ### Gin-Vue-Admin Quick Start Source: https://www.gin-vue-admin.com/guide/video/server Guides users through the initial setup and configuration of Gin-Vue-Admin, including environment setup, initialization, and common tools like Swagger and VSCode. ```APIDOC Quick Start: - Environment Configuration - Initialization Process - Swagger Integration - VSCode Setup - Common Questions ``` -------------------------------- ### Gin-Vue-Admin Quick Start Guide Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose This section provides guidance for quickly starting with Gin-Vue-Admin, including environment configuration, project initialization, AI assistant setup, and using tools like Swagger and VSCode. ```APIDOC Quick Start: Environment Setup: https://www.gin-vue-admin.com/guide/start-quickly/env.html Initialization: https://www.gin-vue-admin.com/guide/start-quickly/initialization.html AI Assistant Config: https://www.gin-vue-admin.com/guide/server/mcp.html Swagger: https://www.gin-vue-admin.com/guide/start-quickly/swagger.html VSCode: https://www.gin-vue-admin.com/guide/start-quickly/vscode.html FAQ: https://www.gin-vue-admin.com/guide/manual/qa.html ``` -------------------------------- ### Gin-Vue-Admin Quick Start Source: https://www.gin-vue-admin.com/guide/server/authorization This section guides users through the initial setup of Gin-Vue-Admin. It includes steps for environment configuration, project initialization, AI assistant setup, and using tools like Swagger and VSCode. ```APIDOC Quick Start: - env.html: Environment configuration steps. - initialization.html: Project initialization process. - mcp.html: AI assistant configuration. - swagger.html: Using Swagger for API documentation. - vscode.html: VSCode setup and usage. - qa.html: Frequently asked questions. ``` -------------------------------- ### Install MySQL on Ubuntu/Debian Source: https://www.gin-vue-admin.com/guide/start-quickly/env Instructions to install MySQL server on Ubuntu or Debian systems using apt, and to start and enable the service. ```Bash sudo apt update sudo apt install mysql-server sudo systemctl start mysql sudo systemctl enable mysql ``` -------------------------------- ### Install and Start Redis on Ubuntu/Debian Source: https://www.gin-vue-admin.com/guide/start-quickly/env Commands to install the Redis server and manage its service on Ubuntu/Debian systems. ```bash sudo apt install redis-server sudo systemctl start redis-server sudo systemctl enable redis-server ``` -------------------------------- ### Install and Start Redis on macOS Source: https://www.gin-vue-admin.com/guide/start-quickly/env Commands to install Redis using Homebrew and start the Redis service on macOS. ```bash brew install redis brew services start redis ``` -------------------------------- ### Install MySQL on macOS Source: https://www.gin-vue-admin.com/guide/start-quickly/env Instructions to install MySQL using Homebrew on macOS and start the MySQL service. ```Bash brew install mysql brew services start mysql ``` -------------------------------- ### Gin-Vue-Admin Deployment Guide Source: https://www.gin-vue-admin.com/guide/video/server Provides instructions for deploying Gin-Vue-Admin in various environments, including Docker, Docker-Compose, Kubernetes, and production setups. ```APIDOC Deployment Guide: - Project Deployment - Docker Deployment - Docker-Compose Deployment - Kubernetes Deployment - Production Environment Deployment - Advanced Deployment Guide ``` -------------------------------- ### Gin-Vue-Admin Deployment Guide Source: https://www.gin-vue-admin.com/guide/plugin/develop This section provides comprehensive instructions for deploying Gin-Vue-Admin, covering Docker, docker-compose, Kubernetes, and production environment setups. It also links to more detailed deployment resources. ```Shell ## 部署指南 [项目上线 ](https://www.gin-vue-admin.com/guide/deployment/) [docker ](https://www.gin-vue-admin.com/guide/deployment/docker.html) [docker-compose ](https://www.gin-vue-admin.com/guide/deployment/docker-compose.html) [kubernetes ](https://www.gin-vue-admin.com/guide/deployment/k8s.html) [生产环境部署 ](https://www.gin-vue-admin.com/guide/deployment/production.html) [更详部署指南 ](https://www.gin-vue-admin.com/empower/index.html) ``` -------------------------------- ### Golang Video Tutorial Series Source: https://www.gin-vue-admin.com/guide/video/golang A comprehensive series of video tutorials covering various aspects of the Golang programming language. Each video focuses on a specific topic, starting from installation and basic concepts to advanced features like concurrency, networking, and generics. ```Golang ## Golang教学 [【golang教学】第一章:golang的安装和编辑工具安装(1010工作室出品)](https://www.bilibili.com/video/BV1Q7411K7ij) [【golang教学】第二章:golang的基础知识——结构,包,变量初探(1010工作室出品)](https://www.bilibili.com/video/BV1W7411N7iq) [【golang教学】第三章:golang基本数据类型和变量初探(1010工作室出品)](https://www.bilibili.com/video/BV1eE411J7QM) [【golang教学】第四章:golang的流程控制语句(1010工作室出品)](https://www.bilibili.com/video/BV1U64y1u74X) [【golang教学】第五章:golang的数组和切片(1010工作室出品)](https://www.bilibili.com/video/BV1P5411t7Wr) [【golang教学】第六章:golang的map声明和使用(1010工作室出品)](https://www.bilibili.com/video/BV1jC4y1x7F7) [【golang教学】第七章:golang的函数func方法(1010工作室出品)](https://www.bilibili.com/video/BV1mg4y187ZN) [【golang教学】第八章:golang的指针和地址(1010工作室出品)](https://www.bilibili.com/video/BV1mg4y187pS) [【golang教学】第九章:golang的结构体struct声明和使用(1010工作室出品)](https://www.bilibili.com/video/BV1Kf4y1S7eP) [【golang教学】第十章:golang的接口interface介绍和工作中的使用(1010工作室出品)](https://www.bilibili.com/video/BV1WA411b7ZF) [【golang教学】第十一章:golang的并发神器goroutine 和 channel (1010工作室出品)](https://www.bilibili.com/video/BV1Vf4y1S75t) [【golang教学】第十二章:golang的断言 Assertion 和 反射 reflect (1010工作室出品)](https://www.bilibili.com/video/BV1S5411x7Bz) [【golang教学】第十三章:context包的基础使用和代码示例(1010工作室出品)](https://www.bilibili.com/video/BV1k54y177yM) [【golang教学】第十四章:并发编程sync包的使用和示例(1010工作室出品)](https://www.bilibili.com/video/BV1EM4y1L7XU) [【golang教学】第十五章:文件操作的基础使用和代码示例(1010工作室出品)](https://www.bilibili.com/video/BV1Wq4y1H7Fe) [【golang教学】第十六章:net包的tcp模块的基础使用和代码示例(1010工作室出品)](https://www.bilibili.com/video/BV1JP4y1s7rS) [【golang教学】第十七章:golang基础之http创建服务端和客户端(1010工作室出品)](https://www.bilibili.com/video/BV1uv411w7dD) [【golang教学】第十八章:golang基础之RPC的客户端和服务端(1010工作室出品)](https://www.bilibili.com/video/BV1gL411x7Ss) [【golang教学】第十九章:泛型的入门和基础使用(1010工作室出品)](https://www.bilibili.com/video/BV1qS4y1Y7k2) [【golang教学】第二十章:使用go搭建简单的websocket(1010工作室出品)](https://www.bilibili.com/video/BV1AY4y1b7tW) ``` -------------------------------- ### Gin-Vue-Admin Plugin Usage Tutorial Source: https://www.gin-vue-admin.com/guide/video/server Explains how to install and develop plugins for the Gin-Vue-Admin framework. ```APIDOC Plugin Usage Tutorial: - Plugin Installation Guide - Plugin Development Tutorial ``` -------------------------------- ### Gin-Vue-Admin Plugin Usage Tutorial Source: https://www.gin-vue-admin.com/guide/plugin/develop This section guides users on how to install and develop plugins for Gin-Vue-Admin. It provides tutorials for both plugin installation and custom plugin development. ```Markdown ## 插件使用教程 [插件安装教程 ](https://www.gin-vue-admin.com/guide/plugin/install.html) [插件研发教程 ](https://www.gin-vue-admin.com/guide/plugin/develop.html) ``` -------------------------------- ### Start Backend Service (GoLand) Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Instructions for starting the Go backend service using the GoLand IDE. This involves opening the main.go file and using the IDE's run/debug features. ```text 1. Open the `main.go` file in GoLand 2. Click the green triangle button next to the line number 3. Alternatively, use the shortcut `Ctrl+Shift+F10` (Windows/Linux) or `Cmd+Shift+R` (macOS) ``` -------------------------------- ### Start Backend Service (Command Line) Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Starts the Go backend service by running the main application file. This is the primary method for launching the server from the command line. ```bash # Run in the server directory go run main.go ``` -------------------------------- ### Gin-Vue-Admin Plugin Usage Tutorial Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose This tutorial covers the process of installing and developing plugins for Gin-Vue-Admin, providing instructions for users and developers. ```APIDOC Plugin Tutorials: Installation: https://www.gin-vue-admin.com/guide/plugin/install.html Development: https://www.gin-vue-admin.com/guide/plugin/develop.html ``` -------------------------------- ### Start Backend Service (VS Code) Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Instructions for starting the Go backend service using the VS Code IDE. This involves using the debug functionality within VS Code. ```text 1. Press `F5` or click the debug button 2. Select "Go: Launch Package" ``` -------------------------------- ### Verify Go Installation Source: https://www.gin-vue-admin.com/guide/start-quickly/env Commands to verify the Go installation and display environment information. This confirms that Go is correctly set up and accessible in the system's PATH. ```Bash go version go env ``` -------------------------------- ### Gin-Vue-Admin Deployment Guide Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose This section covers deployment strategies for Gin-Vue-Admin, including Docker, docker-compose, Kubernetes, and production environment deployment. It also links to more detailed deployment guides. ```APIDOC Deployment: docker: https://www.gin-vue-admin.com/guide/deployment/docker.html docker-compose: https://www.gin-vue-admin.com/guide/deployment/docker-compose.html kubernetes: https://www.gin-vue-admin.com/guide/deployment/k8s.html production: https://www.gin-vue-admin.com/guide/deployment/production.html advanced: https://www.gin-vue-admin.com/empower/index.html ``` -------------------------------- ### Nginx Installation and Configuration Source: https://www.gin-vue-admin.com/guide/deployment Steps to install Nginx, configure it for proxying requests to a backend server, and restart the service. ```Shell yum install -y nginx # Install all modules yum -y install nginx-all-modules.noarch # Start nginx systemctl start nginx && systemctl enable nginx ``` ```Nginx user root; events { worker_connections 1024; ## Default: 1024 } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; index index.php index.html index.htm default.php default.htm default.html; server_name home.mychat.cloud; root 你的dist所在位置; location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://127.0.0.1:8888; # Set the protocol and address of the proxy server, port must be consistent with the backend deployment proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } ``` ```Shell sudo systemctl restart nginx ``` -------------------------------- ### Gin-Vue-Admin Backend Project Guide Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose This guide details the backend project structure and features of Gin-Vue-Admin, including configuration, authentication, authorization, code generation, object storage, multi-database support, and core components like Viper, Zap, and Gorm. ```APIDOC Backend Guide: Overview: https://www.gin-vue-admin.com/guide/server/ Configuration: https://www.gin-vue-admin.com/guide/server/config.html Authentication: https://www.gin-vue-admin.com/guide/server/authentication.html Authorization: https://www.gin-vue-admin.com/guide/server/authorization.html Code Generator: https://www.gin-vue-admin.com/guide/server/code-generator.html Object Storage: https://www.gin-vue-admin.com/guide/server/oss.html Multi-Database: https://www.gin-vue-admin.com/guide/server/multiple-databases.html Strict Auth Mode: https://www.gin-vue-admin.com/guide/server/strict-auth.html Core Components: Viper: https://www.gin-vue-admin.com/guide/server/core/viper.html Zap: https://www.gin-vue-admin.com/guide/server/core/zap.html Gorm: https://www.gin-vue-admin.com/guide/server/gorm.html Timer: https://www.gin-vue-admin.com/guide/server/timer.html MCP AI Integration: https://www.gin-vue-admin.com/guide/server/mcp.html Database Design: https://www.gin-vue-admin.com/guide/server/database-design.html Empowerment Guide: https://www.gin-vue-admin.com/empower/index.html ``` -------------------------------- ### Install Go Dependencies Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Installs Go module dependencies by adding missing modules and removing unused ones. This command ensures all necessary packages are available for the Go backend service. ```bash # Download and tidy dependencies go mod tidy ``` -------------------------------- ### Install Recommended VSCode Extensions Source: https://www.gin-vue-admin.com/guide/start-quickly/vscode Installs a set of recommended VSCode extensions for Go, Vue, TypeScript, Prettier, ESLint, Tailwind CSS, and more to enhance the development experience. ```bash code --install-extension golang.go code --install-extension vue.volar code --install-extension vue.vscode-typescript-vue-plugin code --install-extension esbenp.prettier-vscode code --install-extension dbaeumer.vscode-eslint code --install-extension bradlc.vscode-tailwindcss code --install-extension formulahendry.auto-rename-tag code --install-extension christian-kohler.path-intellisense ``` -------------------------------- ### Install swag CLI Tool Source: https://www.gin-vue-admin.com/guide/start-quickly/swagger Installs the swag CLI tool, which is used to generate OpenAPI documentation from comments in Go source code. Supports direct installation or installation via a Go module proxy for network issues. ```Bash # Install the latest version of the swag tool go install github.com/swaggo/swag/cmd/swag@latest ``` ```Bash # Enable Go Modules go env -w GO111MODULE=on # Configure domestic proxy (choose one) go env -w GOPROXY=https://goproxy.cn,direct # Or use # go env -w GOPROXY=https://goproxy.io,direct # Install swag tool go install github.com/swaggo/swag/cmd/swag@latest ``` ```Bash # Check swag version swag --version # View help information swag --help ``` -------------------------------- ### Install Frontend Dependencies Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Installs project dependencies for the frontend application using npm, yarn, or pnpm. It also notes the required Node.js version. ```text ⚠️ Node.js version requirement Ensure your Node.js version is >= 18.16.2 # Install project dependencies npm install # Or use yarn (if installed) yarn install # Or use pnpm (recommended, faster) pnpm install ``` -------------------------------- ### Verify Node.js Installation Source: https://www.gin-vue-admin.com/guide/start-quickly/env Commands to check the installed versions of Node.js and npm. This is crucial for ensuring compatibility with the project requirements. ```Bash node -v npm -v ``` -------------------------------- ### Gin-Vue-Admin Deployment Source: https://www.gin-vue-admin.com/guide/server/authorization This section covers the deployment process for Gin-Vue-Admin, including instructions for Docker, docker-compose, Kubernetes, and production environments. It also provides links to more comprehensive deployment guides. ```APIDOC Deployment Guide: - deployment/: General deployment information. - docker.html: Deploying with Docker. - docker-compose.html: Deploying with docker-compose. - k8s.html: Deploying with Kubernetes. - production.html: Guidelines for production environment deployment. - empower/index.html: More detailed deployment instructions. ``` -------------------------------- ### Gin-Vue-Admin Backend Development Guide Source: https://www.gin-vue-admin.com/guide/plugin/develop This section details the backend development aspects of Gin-Vue-Admin, focusing on configuration, authentication, authorization, code generation, and core libraries like Viper, Zap, and GORM. It also covers advanced topics such as multi-database support and timer tasks. ```Go ## 后端项目指南 [后端指南 ](https://www.gin-vue-admin.com/guide/server/) [配置文件 ](https://www.gin-vue-admin.com/guide/server/config.html) [认证系统 ](https://www.gin-vue-admin.com/guide/server/authentication.html) [权限系统 ](https://www.gin-vue-admin.com/guide/server/authorization.html) [代码生成器 ](https://www.gin-vue-admin.com/guide/server/code-generator.html) [对象存储 ](https://www.gin-vue-admin.com/guide/server/oss.html) [多数据库支持 ](https://www.gin-vue-admin.com/guide/server/multiple-databases.html) [严格角色模式 ](https://www.gin-vue-admin.com/guide/server/strict-auth.html) [viper ](https://www.gin-vue-admin.com/guide/server/core/viper.html) [zap ](https://www.gin-vue-admin.com/guide/server/core/zap.html) [gorm ](https://www.gin-vue-admin.com/guide/server/gorm.html) [定时任务 ](https://www.gin-vue-admin.com/guide/server/timer.html) [MCP AI助手集成 ](https://www.gin-vue-admin.com/guide/server/mcp.html) [数据库设计 ](https://www.gin-vue-admin.com/guide/server/database-design.html) [开发指导文档 ](https://www.gin-vue-admin.com/empower/index.html) ``` -------------------------------- ### Open Frontend Project Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Opens the frontend project directory in VS Code and prepares it for dependency installation and startup. ```bash # Enter the frontend directory cd web # Open with VS Code code . ``` -------------------------------- ### Execute Database Initialization Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Describes the final steps to initialize the database, including confirming the configuration and clicking the 'Initialize Now' button. It also outlines the post-initialization actions performed by the system. ```text 1. Confirm all information is correct 2. Click the "Initialize Now" button 3. Wait for initialization to complete Upon successful initialization, the system will: * ✅ Create all necessary data tables * ✅ Insert basic data (admin account, menus, permissions, etc.) * ✅ Automatically redirect to the login page ``` -------------------------------- ### Backend Debugging: Using Delve Source: https://www.gin-vue-admin.com/guide/troubleshooting/common-issues Provides instructions on installing and using the Delve debugger for Go applications. Includes commands to install Delve, start a debugging session, and set breakpoints. ```bash # Install Delve go install github.com/go-delve/delve/cmd/dlv@latest # Start debugging dlv debug main.go # Set breakpoints in code (dlv) break main.main (dlv) continue ``` -------------------------------- ### Git Commit Examples Source: https://www.gin-vue-admin.com/guide/best-practices/development-standards Provides examples of commit messages following the specified format for new features, bug fixes, and refactoring, including breaking changes. ```bash # 新功能 git commit -m "feat(user): 添加用户批量导入功能 - 支持Excel文件导入 - 添加数据验证 - 支持导入进度显示 Closes #123" # 修复bug git commit -m "fix(auth): 修复JWT token过期时间计算错误 修复了token过期时间计算不准确的问题, 现在使用UTC时间进行计算。 Fixes #456" # 重构 git commit -m "refactor(api): 重构用户API响应结构 BREAKING CHANGE: 用户API响应格式发生变化 - 将user_info改为userInfo - 添加了权限信息字段" ``` -------------------------------- ### Gin-Vue-Admin Project Structure Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Provides an overview of the Gin-Vue-Admin project's directory structure, highlighting key directories like 'server' for the backend Go project and 'web' for the frontend Vue project. ```Text gin-vue-admin/ ├── server/ # 后端 Go 项目 │ ├── main.go # 程序入口 │ ├── config.yaml # 配置文件 │ └── ... ├── web/ # 前端 Vue 项目 │ ├── src/ # 源代码 │ ├── package.json # 依赖配置 │ └── ... └── README.md # 项目说明 ``` -------------------------------- ### Open Backend Project with IDE Source: https://www.gin-vue-admin.com/guide/start-quickly/initialization Instructions on how to open the Gin-Vue-Admin backend project directory using either GoLand or VS Code. ```Bash # 进入后端目录 cd server # 使用 GoLand 打开(如果已安装) goland . # 或使用 VS Code 打开 code . ``` -------------------------------- ### Role Inheritance Example (Go) Source: https://www.gin-vue-admin.com/guide/server/authorization Demonstrates how to establish role inheritance relationships using Casbin. Shows examples of a user inheriting a role and one role inheriting another role, enabling hierarchical access control. ```go // 设置角色继承关系 e := casbinService.Casbin() e.AddRoleForUser("user1", "role1") // 用户继承角色 e.AddRoleForUser("role1", "role2") // 角色继承角色 ``` -------------------------------- ### Vite Development Server Start Failure Source: https://www.gin-vue-admin.com/guide/troubleshooting/common-issues Resolves issues where the Vite development server fails to start, often due to missing modules like '@vitejs/plugin-vue'. Solutions include reinstalling Vite dependencies and checking the vite.config.js configuration for correct plugin setup and server proxy settings. ```bash npm install @vitejs/plugin-vue @vitejs/plugin-vue-jsx --save-dev ``` ```javascript import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': resolve(__dirname, 'src') } }, server: { port: 8080, proxy: { '/api': { target: 'http://localhost:8888', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') } } } }) ``` -------------------------------- ### Go Initialization for Multiple Databases Source: https://www.gin-vue-admin.com/guide/server/multiple-databases This Go code demonstrates how to initialize the multiple database list after configuring the `db-list` parameter in `config.yaml`. It shows the method call to set up the database connections. ```Go initialize.DBList() # Initialize multiple database list ``` -------------------------------- ### Gin-Vue-Admin Project Introduction Source: https://www.gin-vue-admin.com/guide/video/server Provides an overview of the Gin-Vue-Admin project, its features, and its purpose. ```APIDOC Project Introduction: - Overview of Gin-Vue-Admin - Key features and benefits ``` -------------------------------- ### Get Menu Tree (Go) Source: https://www.gin-vue-admin.com/guide/server/authorization Generates a hierarchical menu tree based on user authority. It fetches menu data from the database and recursively builds the tree structure. ```go package service import ( "your_project/model/system" ) // MenuService handles menu-related operations. type MenuService struct {} // GetMenuTree retrieves the menu tree for a given authority ID. func (menuService *MenuService) GetMenuTree(authorityId string) (menus []system.SysMenu, err error) { menuTree, err := menuService.getMenuTreeMap(authorityId) menus = menuTree["0"] for i := 0; i < len(menus); i++ { err = menuService.getChildrenList(&menus[i], menuTree) } return menus, err } // Placeholder for getMenuTreeMap (implementation not provided in the original text) func (menuService *MenuService) getMenuTreeMap(authorityId string) (map[string][]system.SysMenu, error) { // Implementation details would go here, likely involving database queries return make(map[string][]system.SysMenu), nil } // Placeholder for getChildrenList (implementation not provided in the original text) func (menuService *MenuService) getChildrenList(menu *system.SysMenu, menuTree map[string][]system.SysMenu) error { // Implementation details would go here, recursively building the menu tree return nil } ``` -------------------------------- ### GvaTable Component Test Source: https://www.gin-vue-admin.com/guide/web Example test for the GvaTable component using Vitest and Vue Test Utils. It verifies the rendering of the table and pagination, and checks if the 'page-change' event is emitted correctly. ```javascript // tests/components/GvaTable.test.js import { mount } from '@vue/test-utils' import { describe, it, expect } from 'vitest' import GvaTable from '@/components/gva-table/index.vue' import { ElTable, ElPagination } from 'element-plus' describe('GvaTable', () => { it('renders table with data', () => { const tableData = [ { id: 1, name: '张三', age: 25 }, { id: 2, name: '李四', age: 30 } ] const wrapper = mount(GvaTable, { props: { tableData, total: 2, currentPage: 1, pageSize: 10 }, global: { components: { ElTable, ElPagination } } }) expect(wrapper.find('.gva-table').exists()).toBe(true) expect(wrapper.find('.gva-pagination').exists()).toBe(true) }) it('emits page-change event when page changes', async () => { const wrapper = mount(GvaTable, { props: { tableData: [], total: 100, currentPage: 1, pageSize: 10 } }) await wrapper.vm.handlePageChange(2) expect(wrapper.emitted('page-change')).toBeTruthy() expect(wrapper.emitted('page-change')[0]).toEqual([2]) }) }) ``` -------------------------------- ### Gin-Vue-Admin Project Introduction Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose An overview of the Gin-Vue-Admin project, its purpose, and key features. ```APIDOC Project Introduction: Overview: https://www.gin-vue-admin.com/guide/introduce/project.html ``` -------------------------------- ### Docker Compose Commands Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose Provides essential commands for managing the gin-vue-admin application with Docker Compose. This includes starting services, rebuilding images, running in detached mode, and cleaning up unused Docker images. ```shell # 使用docker-compose启动四个容器 docker-compose -f deploy/docker-compose/docker-compose.yaml up # 如果您修改了某些配置选项,可以使用此命令重新打包镜像 docker-compose -f deploy/docker-compose/docker-compose.yaml up --build # 使用docker-compose 后台启动 docker-compose -f deploy/docker-compose/docker-compose.yaml up -d # 使用docker-compose 重新打包镜像并后台启动 docker-compose -f deploy/docker-compose/docker-compose.yaml up --build -d # 服务都启动成功后,使用此命令行可清除none镜像 docker system prune ``` -------------------------------- ### Gin-Vue-Admin Backend Project Guide Source: https://www.gin-vue-admin.com/guide/video/server Details backend development, including configuration files, authentication and authorization systems, code generation, object storage, multi-database support, strict role mode, and core components like Viper, Zap, and Gorm. Also covers timer tasks and MCP AI assistant integration. ```APIDOC Backend Project Guide: - Configuration Files - Authentication System - Authorization System - Code Generator - Object Storage - Multi-database Support - Strict Role Mode - Core Components: - Viper - Zap - Gorm - Timer Tasks - MCP AI Assistant Integration - Database Design ``` -------------------------------- ### API Calling Convention - JavaScript Source: https://www.gin-vue-admin.com/guide/best-practices/development-standards Defines the standard for naming API functions (verb + resource name) and demonstrates how to use these functions in a Vue component. Includes examples for fetching, creating, updating, and deleting user data. ```javascript // api/user.js import request from '@/utils/request' // API 函数命名:动词 + 资源名 export function getUserList(params) { return request({ url: '/user/getUserList', method: 'post', data: params }) } export function createUser(data) { return request({ url: '/user/register', method: 'post', data }) } export function updateUser(id, data) { return request({ url: `/user/setUserInfo`, method: 'put', data: { ...data, ID: id } }) } export function deleteUser(id) { return request({ url: '/user/deleteUser', method: 'delete', data: { ID: id } }) } // 在组件中使用 import { getUserList, createUser } from '@/api/user' export default { setup() { const fetchUsers = async () => { try { const response = await getUserList({ page: 1, pageSize: 10 }) if (response.code === 0) { userList.value = response.data.list } else { ElMessage.error(response.msg || '获取用户列表失败') } } catch (error) { ElMessage.error('网络错误,请稍后重试') console.error('API调用失败:', error) } } return { fetchUsers } } } ``` -------------------------------- ### Go Unit Test for User Service Source: https://www.gin-vue-admin.com/guide/best-practices/development-standards Example of a Go unit test for a UserService. It demonstrates how to test the CreateUser function using mocks for database interactions and assertions for expected outcomes, including handling user existence errors. ```go // user_service_test.go package service import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func TestUserService_CreateUser(t *testing.T) { // 准备测试数据 user := &User{ Username: "testuser", Email: "test@example.com", Password: "password123", } // 创建mock mockDB := new(MockDB) mockDB.On("Create", mock.AnythingOfType("*User")).Return(nil) // 创建服务实例 service := NewUserService(mockDB, nil) // 执行测试 err := service.CreateUser(user) // 断言结果 assert.NoError(t, err) mockDB.AssertExpectations(t) } func TestUserService_CreateUser_UserExists(t *testing.T) { user := &User{ Username: "existinguser", Email: "existing@example.com", Password: "password123", } mockDB := new(MockDB) mockDB.On("First", mock.AnythingOfType("*User"), mock.Anything).Return(nil) service := NewUserService(mockDB, nil) err := service.CreateUser(user) assert.Error(t, err) assert.Equal(t, ErrUserExists, err) } ``` -------------------------------- ### System Configuration (YAML) Source: https://www.gin-vue-admin.com/guide/server/gorm Example YAML configuration for the system settings, including environment, server address, database type selection (MySQL or PostgreSQL), and other operational parameters. ```yaml system: env: 'public' addr: 8888 db-type: 'mysql' oss-type: 'local' use-multipoint: false iplimit-count: 15000 iplimit-time: 3600 ``` -------------------------------- ### Register Database Tables with Gorm Source: https://www.gin-vue-admin.com/guide/generator/server This Go code snippet demonstrates how to initialize the database connection and register various system, example, and autogenerated tables using Gorm's AutoMigrate function. It supports different database types and logs success or failure. ```go package initialize import ( "os" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/autocode" "github.com/flipped-aurora/gin-vue-admin/server/model/example" "github.com/flipped-aurora/gin-vue-admin/server/model/system" "go.uber.org/zap" "gorm.io/gorm" ) // Gorm 初始化数据库并产生数据库全局变量 // Author SliverHorn func Gorm() *gorm.DB { switch global.GVA_CONFIG.System.DbType { case "mysql": return GormMysql() case "pgsql": return GormPgSql() default: return GormMysql() } } // RegisterTables 注册数据库表专用 // Author SliverHorn func RegisterTables(db *gorm.DB) { err := db.AutoMigrate( // 系统模块表 system.SysApi{}, system.SysUser{}, system.SysBaseMenu{}, system.JwtBlacklist{}, system.SysAuthority{}, system.SysDictionary{}, system.SysOperationRecord{}, system.SysAutoCodeHistory{}, system.SysDictionaryDetail{}, system.SysBaseMenuParameter{}, // 示例模块表 example.ExaFile{}, example.ExaCustomer{}, example.ExaFileChunk{}, example.ExaFileUploadAndDownload{}, // 自动化模块表 // Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT. autocode.AutoCodeExample{}, // Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT. ) if err != nil { global.GVA_LOG.Error("register table failed", zap.Error(err)) os.Exit(0) } global.GVA_LOG.Info("register table success") } ``` -------------------------------- ### Casbin Service Implementation (Go) Source: https://www.gin-vue-admin.com/guide/server/authorization Provides methods for managing Casbin authorization policies. Includes functions to update policies, retrieve policies by authority ID, clear policies, and get the Casbin enforcer instance. Relies on global Casbin enforcer and request structures. ```go type CasbinService struct {} // UpdateCasbin 更新Casbin权限 func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { casbinService.ClearCasbin(0, authorityId) rules := [][]string{} for _, v := range casbinInfos { rules = append(rules, []string{authorityId, v.Path, v.Method}) } e := casbinService.Casbin() success, _ := e.AddPolicies(rules) if !success { return errors.New("存在相同api,添加失败,请联系管理员") } return nil } // GetPolicyPathByAuthorityId 获取权限列表 func (casbinService *CasbinService) GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) { e := casbinService.Casbin() list := e.GetFilteredPolicy(0, authorityId) for _, v := range list { pathMaps = append(pathMaps, request.CasbinInfo{ Path: v[1], Method: v[2], }) } return pathMaps } // ClearCasbin 清除权限 func (casbinService *CasbinService) ClearCasbin(v int, p ...string) bool { e := casbinService.Casbin() success, _ := e.RemoveFilteredPolicy(v, p...) return success } // Casbin 获取Casbin实例 func (casbinService *CasbinService) Casbin() *casbin.Enforcer { return global.GVA_CASBIN } ``` -------------------------------- ### Auto Generate API Endpoints Source: https://www.gin-vue-admin.com/guide/generator/server This Go function automatically generates API endpoints for CRUD operations (Create, Delete, Update, Get) based on provided struct information. It ensures that API entries are created only if they don't already exist, using a database transaction for atomicity. ```go //@author: [piexlmax](https://github.com/piexlmax) //@author: [SliverHorn](https://github.com/SliverHorn) //@function: CreateApi //@description: 自动创建api数据, //@param: a *model.AutoCodeStruct //@return: error func AutoCreateApi(a *model.AutoCodeStruct) (err error) { var apiList = []model.SysApi{ { Path: "/" + a.Abbreviation + "/" + "create" + a.StructName, Description: "新增" + a.Description, ApiGroup: a.Abbreviation, Method: "POST", }, { Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName, Description: "删除" + a.Description, ApiGroup: a.Abbreviation, Method: "DELETE", }, { Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName + "ByIds", Description: "批量删除" + a.Description, ApiGroup: a.Abbreviation, Method: "DELETE", }, { Path: "/" + a.Abbreviation + "/" + "update" + a.StructName, Description: "更新" + a.Description, ApiGroup: a.Abbreviation, Method: "PUT", }, { Path: "/" + a.Abbreviation + "/" + "find" + a.StructName, Description: "根据ID获取" + a.Description, ApiGroup: a.Abbreviation, Method: "GET", }, { Path: "/" + a.Abbreviation + "/" + "get" + a.StructName + "List", Description: "获取" + a.Description + "列表", ApiGroup: a.Abbreviation, Method: "GET", }, } err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { for _, v := range apiList { var api model.SysApi if errors.Is(tx.Where("path = ? AND method = ?", v.Path, v.Method).First(&api).Error, gorm.ErrRecordNotFound) { if err := tx.Create(&v).Error; err != nil { // 遇到错误时回滚事务 return err } } } return nil }) return err } ``` -------------------------------- ### GoLand Configuration Suggestions Source: https://www.gin-vue-admin.com/guide/start-quickly/env Recommendations for configuring GoLand for optimal development with gin-vue-admin, focusing on Go Modules, code formatting with gofmt and goimports, and code inspection with golint and go vet. ```APIDOC GoLand Configuration Suggestions: 1. Go Modules: Ensure Go Modules support is enabled. 2. Code Formatting: Configure gofmt and goimports. 3. Code Inspection: Enable golint and go vet. ``` -------------------------------- ### Gin-Vue-Admin Code Generator Guide Source: https://www.gin-vue-admin.com/guide/deployment/docker-compose This guide explains how to use the code generator in Gin-Vue-Admin, covering automated package generation, server-side code generation, and form generation for both development and production environments. ```APIDOC Code Generator: Automated Package: https://www.gin-vue-admin.com/guide/generator/package.html Server Usage: https://www.gin-vue-admin.com/guide/generator/server.html Form Generator (Dev): https://www.gin-vue-admin.com/guide/generator/web.html Form Generator (Prod): https://www.gin-vue-admin.com/guide/generator/web-produce.html ```