+
Skip to content

morehao/gocli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 简体中文

gocli Introduction

gocli is a command-line toolset written in Go, designed to boost development efficiency. It currently includes features for code generation and quick project scaffolding.

Quick Start

Installation

go install github.com/morehao/gocli@latest

generate

generate is a tool that generates code quickly based on template files. The project structure and style are modeled after go-gin-web.

Features

  • Quickly generate a complete CRUD interface for a new module based on a MySQL table, ready for use.
  • Generate model and dao layer code based on MySQL table name.
  • Quickly scaffold a standard API interface from configuration.
  • Customize layer names, parent directories, and layer name prefixes.
  • Automatically formats the generated code using gofmt.

Prerequisites

  1. Run the command in the root directory of the corresponding application, e.g., xxxx/go-gin-web/demoapp. To generate code under demoapp, execute the command inside that folder.
  2. Ensure that the application contains a configuration file named code_gen.yaml. Example:
mysql_dsn: root:123456@tcp(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local
#layer_parent_dir_map:
#  model: model
#  dao: dao
#layer_name_map:
#  model: mysqlmodel
#  dao: mysqldao
#layer_prefix_map:
#  service: srv
module:
  package_name: user
  description: User login records
  table_name: user_login_log
model:
  package_name: user
  description: User
  table_name: user
api:
  package_name: user
  target_filename: user_login_log.go
  function_name: Delete
  http_method: POST
  description: Delete login record
  api_doc_tag: User login records

Configuration Reference

Field Description Example
mysql_dsn MySQL DSN connection string root:123456@tcp(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local
layer_parent_dir_map Map of parent directories for layers model: model
layer_name_map Mapping to rename code layers model: mysqlmodel
layer_prefix_map Prefix mapping for layer names service: srv

Module Configuration

Field Description Example
package_name Go package name user
description Description of the module User login records
table_name MySQL table name user_login_log

Model Configuration

Field Description Example
package_name Model package name user
description Description of the model User
table_name Table name in database user

API Configuration

Field Description Example
package_name API package name user
target_filename Name of the generated file user_login_log.go
function_name Generated function name Delete
http_method HTTP method for the API POST
description Description of the API Delete login record
api_doc_tag API doc tag User login records

Command Usage

# Generate module code
gocli generate -m module

# Generate model code
gocli generate -m model

# Generate API interface code
gocli generate -m api

The go-gin-web project contains example usage in its Makefile.


cutter

cutter is a CLI tool for quickly creating a new Go project based on an existing template project.

Features

  • Must be executed from the root directory of the template project.
  • Filters copied files using .gitignore.
  • Replaces import paths automatically.
  • Updates the module name in go.mod.
  • Deletes the .git directory from the new project.

⚠️ Note: Be sure to run the command from the root directory of the template project.

Command Usage

cd /appTemplatePath
gocli cutter -d /yourAppPath
  • -d, --destination: Destination path for the new project, e.g., /user/myApp (required).

About

A Go command-line tool for code generation and other functionalities

Resources

License

Stars

Watchers

Forks

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载