{"id":15095912,"url":"https://github.com/mqenergy/gin-framework","last_synced_at":"2025-04-07T09:20:18.586Z","repository":{"id":41281482,"uuid":"459378358","full_name":"MQEnergy/gin-framework","owner":"MQEnergy","description":" :zap::rocket:  Based on the gin framework, we have developed a user-friendly, simple, and fast development framework for API programming using go1.18+","archived":false,"fork":false,"pushed_at":"2024-08-21T14:03:23.000Z","size":182,"stargazers_count":290,"open_issues_count":0,"forks_count":16,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T07:06:04.154Z","etag":null,"topics":["amqp","casbin","gin","gin-framework","go","go-bindata","go-redis","golang","gorm","grpc","jwt","logrus","migration","rabbitmq","snowflake","validator","viper","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MQEnergy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-15T00:57:06.000Z","updated_at":"2025-03-25T09:49:08.000Z","dependencies_parsed_at":"2024-12-03T22:00:39.570Z","dependency_job_id":"9787f8ed-c666-44a6-8eef-fb253cd7cde0","html_url":"https://github.com/MQEnergy/gin-framework","commit_stats":{"total_commits":112,"total_committers":1,"mean_commits":112.0,"dds":0.0,"last_synced_commit":"70ec94b1cbbd7fe66a722e5c5f21e7a30cd5abd3"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgin-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgin-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgin-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MQEnergy%2Fgin-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MQEnergy","download_url":"https://codeload.github.com/MQEnergy/gin-framework/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622983,"owners_count":20968575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amqp","casbin","gin","gin-framework","go","go-bindata","go-redis","golang","gorm","grpc","jwt","logrus","migration","rabbitmq","snowflake","validator","viper","websocket"],"created_at":"2024-09-25T15:43:41.182Z","updated_at":"2025-04-07T09:20:18.565Z","avatar_url":"https://github.com/MQEnergy.png","language":"Go","readme":"# :zap::rocket: Based on the gin framework, we have developed a user-friendly, simple, and fast development framework for API programming using go1.18+.\n\n```\n ██████╗ ██╗███╗   ██╗      ███████╗██████╗  █████╗ ███╗   ███╗███████╗██╗    ██╗ ██████╗ ██████╗ ██╗  ██╗\n██╔════╝ ██║████╗  ██║      ██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝██║    ██║██╔═══██╗██╔══██╗██║ ██╔╝\n██║  ███╗██║██╔██╗ ██║█████╗█████╗  ██████╔╝███████║██╔████╔██║█████╗  ██║ █╗ ██║██║   ██║██████╔╝█████╔╝\n██║   ██║██║██║╚██╗██║╚════╝██╔══╝  ██╔══██╗██╔══██║██║╚██╔╝██║██╔══╝  ██║███╗██║██║   ██║██╔══██╗██╔═██╗\n╚██████╔╝██║██║ ╚████║      ██║     ██║  ██║██║  ██║██║ ╚═╝ ██║███████╗╚███╔███╔╝╚██████╔╝██║  ██║██║  ██╗\n ╚═════╝ ╚═╝╚═╝  ╚═══╝      ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝╚══════╝ ╚══╝╚══╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝\n```\n[![GoDoc](https://godoc.org/github.com/MQEnergy/gin-framework/?status.svg)](https://pkg.go.dev/github.com/MQEnergy/gin-framework)\n[![Go Report Card](https://goreportcard.com/badge/github.com/MQEnergy/gin-framework)](https://goreportcard.com/report/github.com/MQEnergy/gin-framework)\n[![codebeat badge](https://codebeat.co/badges/1bf7dd49-1283-4ec9-b56e-a755e1e9c8dd)](https://codebeat.co/projects/github-com-mqenergy-gin-framework-main)\n[![GitHub license](https://img.shields.io/github/license/MQEnergy/gin-framework)](https://github.com/MQEnergy/gin-framework/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/MQEnergy/gin-framework)](https://github.com/MQEnergy/gin-framework/stargazers)\n\n[中文文档](README.zh_CN.md)\n\n# I、Directory Structure\n\n```\n├── Dockerfile\n├── LICENSE\n├── Makefile                        # makefile\n├── README.md\n├── app                             # Directory holding modules\n│   ├── amqp                        # Message queue\n│   ├── controller                  # Controller\n│   └── service                     # Service layer\n├── bootstrap                       # Initialization program loading service\n├── cmd                             # Command commands\n│   ├── admin.go                    # Generate admin backend account\n│   ├── controller.go               # Generate controller\n│   ├── migrate.go                  # Generate migrate database migration\n│   ├── model.go                    # Generate model data model\n│   ├── service.go                  # Generate service layer\n├── config\n│   ├── config.go                   # Map yaml configuration file to structure\n│   ├── white_list.go               # Whitelist\n│   └── yaml                        # yaml configuration file directory\n├── global                          # Global variables and global methods\n├── go.mod\n├── go.sum\n├── main.go\n├── middleware                      # Middleware\n├── migrations                      # Migration files\n├── models                          # Models\n├── pkg                             # Custom common services, JWT, helper functions, etc.\n│   ├── auth                        # jwt\n│   ├── lib                         # Log service, database service, redis service, etc.\n│   ├── paginator                   # Paginator\n│   ├── response                    # Http request returns status and formatting\n│   ├── util                        # Helper function\n│   └── validator                   # Parameter validator\n├── router                          # Route configuration\n├── runtime                         # Files produced at runtime, such as logs, etc.\n├── types                           # All custom structures\n```\n\n#### Currently integrated and implemented:\n- [x] Support for [jwt](https://github.com/dgrijalva/jwt-go) Authorization token validation component\n- [x] Support for [cors](https://github.com/gin-contrib/cors) interface cross-domain component\n- [x] Support for [gorm](https://gorm.io) database operation component\n- [x] Support for [gorm-model](https://github.com/MQEnergy/gorm-model) self-implemented model structure based on gorm-generated mapping data tables\n- [x] Support for [logrus](https://github.com/sirupsen/logrus) log collection component\n- [x] Support for [go-redis](https://github.com/go-redis/redis) redis connection component\n- [x] Support for [migrate](https://github.com/golang-migrate/migrate) database migration component\n- [x] Support for [controller, service](https://github.com/MQEnergy/gin-framework/tree/main/command) command-line code generation tool\n- [x] Support for [go-websocket](https://github.com/MQEnergy/go-websocket) real-time communication component based on gorilla/websocket (single client, multiple clients, groups, broadcast, etc.)\n- [x] Support for [go-rabbitmq](https://github.com/MQEnergy/go-rabbitmq) message queue component implemented based on rabbitmq's official [amqp](https://github.com/streadway/amqp) consumer and producer encapsulation\n- [x] Support for [casbin](https://github.com/casbin/casbin) rbac permissions integrated in middleware [casbin_auth.go](https://github.com/MQEnergy/gin-framework/blob/main/middleware/casbin_auth.go)\n- [x] Support for [requestId](https://github.com/gin-contrib/requestid) middleware that implements convenient tracking log middleware [requestid_auth.go](https://github.com/MQEnergy/gin-framework/blob/main/middleware/requestid_auth.go)\n- [x] Support for [viper](https://github.com/spf13/viper) configuration file parsing component for yaml, json, toml, etc.\n- [x] Support for [validator](https://github.com/go-playground/validator) data field validator component, supporting Chinese language\n- [x] Support for [snowflake](https://github.com/bwmarrin/snowflake) generate globally unique IDs with snowflake algorithm\n- [x] Implementation of ip whitelist configuration integrated in middleware [ip_auth.go](https://github.com/MQEnergy/gin-framework/blob/main/middleware/ip_auth.go)\n- [x] Implementation of [ticker](https://github.com/MQEnergy/gin-framework/blob/main/pkg/util/ticker.go) timer component\n- [x] Implementation of [pagination](https://github.com/MQEnergy/gin-framework/blob/main/pkg/paginator/pagination.go) builder component based on gorm\n- [x] Implementation of [code](https://github.com/MQEnergy/gin-framework/tree/main/pkg/response/code.go) unified defined return code, [exception](https://github.com/MQEnergy/gin-framework/tree/main/pkg/response/exception.go) unified error return handling component\n  \n#### Next step plans:\n- [ ] Support cron for schedule tasks\n- [ ] Support performance analysis component [pprof](https://github.com/gin-contrib/pprof)\n- [ ] Support internal link tracking for trace project\n- [ ] Support interface flow control component [rate](https://pkg.go.dev/golang.org/x/time/rate)\n- [ ] Support [grpc](https://github.com/grpc/grpc-go) rpc component\n\n# II. Start the service.\n\n```\nNote that before starting, you need to enable the MySQL and Redis services, and configure the MySQL and Redis settings in the config.dev.yaml file (which defaults to the dev environment).\n```\n\n## 1、Install dependencies and initialize.\n\n```bash\ngo mod tidy \n```\n\n## 2、Service started.\n\n```bash\ngo run main.go \n\n# View parameters of main.go.\ngo run main.go --help\n```\n\n## 3、The visit indicates that successful startup.\nRequest：http://127.0.0.1:9527/ping\n```json\n{\n    \"status\": 200,\n    \"errcode\": 0,\n    \"requestid\": \"9ac7f4f2-1271-4f87-8df7-599a478af9cb\",\n    \"message\": \"Pong!\",\n    \"data\": \"\"\n}\n```\n\n## 4、Install hot updates.\n\n```bash\ngo install github.com/cosmtrek/air@latest\n```\n\nType in the command line: \"air\" to execute hot update. The code edits will update automatically.\n\n## 5、Deploy Casbin authorization (Important! (Follow the steps below))\n```\nThis step is intended for accessing permission for backend interfaces.\n```\n### 1）Perform migrate.\n```bash\ngo run main.go migrate -s=all\n\n# Please check the specific parameters in the \"help\" section.\ngo run main.go migrate -help\n```\n### 2）Request the `/routes` interface.\n```\nThis interface will create a super administrator role based on casbin.\n```\n\n## 6、Packaging and Launching Online\n\n```bash\n# Viewing the make command line\nmake help\n\n# Basic packaging to generate executable file (based on the current system)\nmake build\n\n# Packaging for Windows\nmake windows\n\n# Packaging for Darwin\nmake darwin\n\n# Packaging for Linux\nmake linux\n```\nView packaged files in the releases section.\n\n# III、Component Usage\n\n## 1、Query pagination constructor based on GORM.\n\n```go\nimport \"github.com/MQEnergy/gin-framework/pkg/paginator\"\n```\n\n### I、Basic Usage\n#### 1）Basic usage of pagination for a single table:\n\n```go\nvar memberList = make([]models.GinAdmin, 0)\npaginator, err := paginator.NewBuilder().\n    WithDB(global.DB).\n    WithModel(models.GinAdmin{}).\n    WithField([]string{\"password\", \"salt\", \"updated_at\", \"_omit\"}).\n    WithCondition(\"id = ?\", 1).\n    Pagination(memberList, 1, 10)\nreturn paginator, err\n```\n\n#### 2）Usage of join queries in databases:\nDefine receiving struct.\n```go\ntype BaseUser models.GinUser\ntype GinUserInfo models.GinUserInfo\n\n// UserList get user lists.\ntype UserList struct {\n\tBaseUser\n\tGinUserInfo `gorm:\"foreignKey:user_id\" json:\"user_info\"`\n}\n```\n\nUsage 1:\n```go\nvar userList = make([]user.UserList, 0)\npagination, err := paginator.NewBuilder().\n    WithDB(global.DB).\n    WithModel(models.GinUser{}).\n    WithFields(models.GinUser{}, models.GinUserTbName, []string{\"password\", \"salt\", \"_omit\"}).\n    WithFields(models.GinUserInfo{}, models.GinUserInfoTbName, []string{\"id\", \"user_id\", \"role_ids\"}).\n    WithJoins(\"left\", []paginator.OnJoins{{\n        LeftTableField:  paginator.JoinTableField{Table: models.GinUserTbName, Field: \"id\"},\n        RightTableField: paginator.JoinTableField{Table: models.GinUserInfoTbName, Field: \"user_id\"},\n    }}).\n    Pagination(\u0026userList, requestParams.Page, global.Cfg.Server.DefaultPageSize)\nreturn pagination, err\n```\n\nUsage two:\n```go\nvar userList = make([]user.UserList, 0)\nmultiFields := []paginator.SelectTableField{\n    {Model: models.GinUser{}, Table: models.GinUserTbName, Field: []string{\"password\", \"salt\", \"_omit\"}},\n    {Model: models.GinUserInfo{}, Table: models.GinUserInfoTbName, Field: []string{\"user_id\", \"role_ids\"}},\n}\t\npagination, err := paginator.NewBuilder().\n    WithDB(global.DB).\n    WithModel(models.GinUser{}).\n    WithMultiFields(multiFields).\n    WithJoins(\"left\", []paginator.OnJoins{{\n        LeftTableField:  paginator.JoinTableField{Table: models.GinUserTbName, Field: \"id\"},\n        RightTableField: paginator.JoinTableField{Table: models.GinUserInfoTbName, Field: \"user_id\"},\n    }}).\n    Pagination(\u0026userList, requestParams.Page, global.Cfg.Server.DefaultPageSize)\nreturn pagination, err\n```\n\n#### 3）Preloading query usage (strongly recommended usage):\n\n```\nNote:\nThere is a slight difference between the struct defined by the preload method and the struct defined by the joins query. The name of the struct defined by the preload method must be consistent with the name of the struct for the current table of the model. Also, the name of the struct for the associated table cannot be the same as the name of the struct for the model. For example, the definition of \"UserInfo\" is as follows:\n```    \n\nDefinition of receiving a struct.\n```go\ntype BaseUser models.GinUser\ntype GinUserInfo models.GinUserInfo\n\ntype GinUser struct {\n\tBaseUser\n\tUserInfo GinUserInfo `gorm:\"foreignKey:user_id\" json:\"user_info\"`\n}\n```\n\nUsage instructions as follows:\n```go\nvar userList = make([]user.GinUser, 0)\npagination, err := paginator.NewBuilder().\n    WithDB(global.DB).\n    WithModel(models.GinUser{}).\n    WithPreload(\"UserInfo\").\n    Pagination(\u0026userList, requestParams.Page, global.Cfg.Server.DefaultPageSize)\nreturn pagination, err\n```\n```\nThis method does not recommend using WithFields or WithField to query fields. Instead, it is recommended to directly define the query fields specified by the receiving struct.\n```\n\nVisit address: http://127.0.0.1:9527/user/index?page=1 The returned data format is as follows:\n\n```json\n{\n  \"status\": 200,\n  \"errcode\": 0,\n  \"requestid\": \"9ac7f4f2-1271-4f87-8df7-599a478af9cb\",\n  \"message\": \"Request Success\",\n  \"data\": {\n    \"list\": [],\n    \"current_page\": 1,\n    \"total\": 2,\n    \"last_page\": 1,\n    \"per_page\": 10\n  }\n}\n```\n#### 4）View case:\n1) Usage: Retrieve User List:\n```\nentities/user/gin_user.go\napp/controller/backend/user.go\napp/service/backend/user.go\nrouter/routes/common.go\n```\n### II. Specific Methods\n\u003cdetails\u003e\n\u003csummary\u003eView usage.\u003c/summary\u003e\n\n#### 1）`Must be used in a chained operation.` DB Connection Method\n```go\nWithDB(db *gorm.DB) *PageBuilder\n```\n\n#### 2）`Must be used in a chained operation.` Model connection method.\n```go\nWithModel(model interface{}) *PageBuilder\n```\n\nPass the main table model as a parameter for the query, for example: models.GinAdmin. You cannot pass a structure address as a parameter, like \u0026models.GinAdmin.\n\n#### 3）`Not necessary in chained operations.` Single table query or filtering field method.\n```go\nWithField(fields []string) *PageBuilder \n```\n\nThe last parameter of \"fields\" defaults to \"_select\" (can be omitted), but if \"_omit\" is passed, it filters out the fields transmitted earlier.\n\nNote:\n- _select / _omit must be the last parameters.\n- WithModel parameter cannot be passed as a pointer to a struct. For example: \u0026models.GinAdmin must be models.GinAdmin, otherwise the _omit parameter will be ineffective.\n- This note applies to the WithFields method and WithMultiFields method.\n\nUsage as follows:\n```go\n// Indicates filtering of front fields.\nWithField([]string{\"created_at\", \"updated_at\", \"_omit\"})\n\n// Indicates the fields to be queried.\nWithField([]string{\"created_at\", \"updated_at\", \"_select\"})\nWithField([]string{\"created_at\", \"updated_at\"})\n```\n\n#### 4）`Not necessary in chain operations.` Multi-table queries or filtering field methods (when using the preload mode, there may be issues with associated table queries, and it is not recommended to use the preload association query method).\n```go\nWithFields(model interface{}, table string, fields []string) *PageBuilder\n```\nThe last argument for fields is default to \"_select\" (can be omitted), if \"_omit\" is passed, it will filter the fields transmitted earlier.\n\nUsage as follows：\n```go\n// Indicates filtering the preceding field.\nWithFields(models.GinUser{}, models.GinUserTbName, []string{\"password\", \"salt\", \"_omit\"})\n\n// \"Indicates the field before the search.\"\nWithFields(models.GinUserInfo{}, models.GinUserInfoTbName, []string{\"id\", \"user_id\", \"role_ids\", \"_select\"})\nWithFields(models.GinUserInfo{}, models.GinUserInfoTbName, []string{\"id\", \"user_id\", \"role_ids\"})\n```\n\n#### 5）`Not necessary in chain operations.` Multiple table and field queries (can replace WithFields method)\n```go\nWithMultiFields(fields []SelectTableField) *PageBuilder\n```\n\nUsage as follows：\n```go\nWithMultiFields([]paginator.SelectTableField{\n    {Model: models.GinUser{}, Table: models.GinUserTbName, Field: []string{\"password\", \"salt\", \"_omit\"}},\n    {Model: models.GinUserInfo{}, Table: models.GinUserInfoTbName, Field: []string{\"id\", \"user_id\", \"role_ids\"}},\n})\n```\n\n#### 6）`Not necessary in chain operations.` Multiple table association query with proactive preloading (conditions not currently supported).\n    \n```go\n WithPreloads(querys []string) *PageBuilder \n```\n\nUsage as follows：\n```go\nWithPreloads([]string{\"UserInfo\", \"UserRecord\"})\n```\n\n#### 7）`Not necessary in chain operations.` Active preloading of associated queries (can pass conditions, conditions refer to Gorm).\n\n```go\nWithPreload(query string, args ...interface{}) *PageBuilder\n```\n\nUsage as follows：\n```go\nWithPreload(\"UserInfo\", \"user_id = ?\", \"1\")\n```\n\n#### 8）`Not necessary in chain operations.` Method for Data Query Conditions.\n\n```go\nWithCondition(query interface{}, args ...interface{}) *PageBuilder\n```\n\nPass in query conditions that support the querying format used in the 'where' conditions in GORM (non-struct format). The 'query' and 'args' parameters should follow the same method of passing in 'where' conditions as in GORM.\n\n#### 9）`Not necessary in chain operations.` Method for Data Query Conditions.\n\n```go\nWithJoins(joinType string, joinFields []OnJoins) *PageBuilder\n```\n\njoinType: Type of join. It can be left, right or inner. joinFields structure: LeftTableField, such as the main table's ID, and RightTableField, such as the related table's main table ID.\n\nUsage as follows：\n```go\nWithJoins(\"left\", []paginator.OnJoins{{\n    LeftTableField:  paginator.JoinTableField{Table: models.GinUserTbName, Field: \"id\"},\n    RightTableField: paginator.JoinTableField{Table: models.GinUserInfoTbName, Field: \"user_id\"},\n}})\n```\n\n#### 10）`The last link must be in the chain operation.` Page return method.\n\n```go\nPagination(dst interface{}, currentPage, pageSize int) (Page, error)\n```\n\n\"dst\" is a \"struct\" structure that receives incoming data. Note: It must be passed in application mode, such as \"\u0026userList\". \"model\" and \"currentPage\" represent the current page number, and \"pageSize\" represents the number of queries per page.\n\n#### 11）`Not necessary in chain operations.` Connecting with native query method.\n\n```go\n NewDB() *gorm.DB\n```\nAfter using this method, all methods inside the pagination for chained operations are unavailable. You can continue using the native methods of GORM afterwards.\n\nUsage as follows：\n```go\nNewDB().Where(\"id = ?\", id).First(\u0026userList)\n```\n\n#### 12）Get current page number.\n\n```go\npaginator.CurrentPage\n```\n\n#### 13）Get paginated list.\n\n```go\npaginator.List\n```\n\n#### 14）Get total number of data.\n\n```go\npaginator.Total\n```\n\n#### 15）Get the last page number.\n\n```go\npaginator.LastPage\n```\n\n#### 16）Get the number of data per page.\n\n```go\npaginator.PerPage\n```\n\u003c/details\u003e\n\n## 2、Upload component based on Gin.\n\n```go\nUploadFile(path string, r *gin.Context) (*FileHeader, error)\n```\n\nBy default, the files are stored in the \"upload\" directory of the project. If it does not exist, it will be created automatically. The path will be \"upload\" directory module directory, such as \"user\". The directory structure will be \"upload/user/{yyyy-mm-dd}/...\".\n\nUsage as follows：\n```\napp/controller/backend/attachment.go\npkg/util/upload.go\nrouter/routes/common.go\n```\n## 3、Using RabbitMQ Component\nConfigure the amqp parameters in the yaml configuration file.\n### 1）Start the consumer.\nTest case\n```shell\ngo run command/test/consumer.go\n```\n### 2）Start the producer.\nTest case\n```shell\ngo run command/test/producer.go\n```\n\n# IV、Tools\n\nRunning \"go run main.go --help\" will display the following command set.\n\n```\nCOMMANDS:\n  migrate     Create a migration command\n  account     Create a new admin account\n  model       Create a new model class\n  controller  Create a new controller class\n  service     Create a new service class\n  help, h     Shows a list of commands or help for one command\n```\n\n## 1、Execute migrate.\n\u003cdetails\u003e\n\u003csummary\u003eView Usage\u003c/summary\u003e\n\n```bash\n# Install migrate cli tool.\ncurl -L https://github.com/golang-migrate/migrate/releases/download/$version/migrate.$platform-amd64.tar.gz | tar xvz\n\n# MacOS Installation\nbrew install golang-migrate\n\n# Install Window with scoop https://scoop.sh/\nscoop install migrate\n\n# \"Creating migration file syntax, for example:\"\nmigrate create -ext sql -dir migrations -seq create_users_table\n\n# The first way to execute migration.\n# Carrying out migration operation:\nmigrate -database 'mysql://root:123456@tcp(127.0.0.1:3306)/gin_framework' -path ./migrations up\n# Performing rollback operation:\nmigrate -database 'mysql://root:123456@tcp(127.0.0.1:3306)/gin_framework' -path ./migrations down\n\n# The second way to perform migration.\n# View help command.\ngo run main.go migrate --help\n\n# The format is as follows：\ngo run main.go migrate -s {step} -e {env}\n# env: Keep consistent with the config.*.yaml file among dev, test, and prod. The default is dev.\n# step: The number of migration files to be executed (or rolled back), for example, 1, 2, 3... If you want to execute all, use \"all\".\n\n# Perform all migration operations:\ngo run main.go migrate -s all\n\n# Perform partial migration operations：\n# eg.：go run main.go migrate -s 1\n\n# Performing rollback operation：\n# eg.：go run main.go migrate -s -1\n```\n\u003c/details\u003e\n\n## 2、Automatically generate models.\n\n```bash\n# Execute the command to generate all models.\ngo run main.go model -tb=all {env}\n\n# Please refer to the help for specific parameters.\ngo run main.go model -help\n```\n\n## 3、Auto-generate controller.\n\n```bash\ngo run main.go controller -c={controller name} -m={module name}\n# eg.：go run main.go controller -c=admin -m=backend\n\n# Please refer to the help for specific parameters.\ngo run main.go controller -help\n```\n\n## 4、Automatically generating service.\n\n```bash\ngo run main.go service -s={service name} -m={module name}\n# The module name is the module named \"name\" located in the app/controller directory.\n# eg.：go run main.go service -s=admin -m=backend\n\n# Please refer to the help for specific parameters.\ngo run main.go service -help\n```\n\n## 5、Create a back-end administrator account (based on the gin_admin table, you can modify the code based on other tables as needed).\n\n```bash\ngo run main.go account -c={account name} -p={password}  \n\n# Check the specific parameters in the help documentation.\ngo run main.go account -help\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmqenergy%2Fgin-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmqenergy%2Fgin-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmqenergy%2Fgin-framework/lists"}