Coder Social home page Coder Social logo

gins-cli's Introduction

一、介绍

1、功能

  • 快速创建golang标准工程结构的web项目,并且底层是gin框架
  • 自定义的统一响应输出结构
  • 支持swag生成接口文档
  • 支持air包热加载
  • 支持zap日志库进行全量日志、错误日志记录
  • 支持makefile管理项目的启动和构建

2、本工具创建的项目目录结构

主要包含如下目录

  • configs:配置文件
  • docs:文档集合
  • global:全局变量
  • internal:
    • api:处理入参层
    • dao:数据访问层,所有与数据相关的操作都会在dao层,比如Mysql,Redis等
    • middleware:HTTP中间件
    • model:模型层,用于存放model对象
    • routers:路由相关的逻辑
    • service:项目核心业务逻辑
  • pkg:项目相关的模块包
  • storage:项目生成的临时文件
  • third_party:第三方的资源工具,如Swagger UI
  • Makefile:构建、运行、打包脚本
  • .air.toml: 项目热加载配置文件

二、工具使用

1、安装前置依赖

1.1 安装swag

使用的是swag库

go install github.com/swaggo/swag/cmd/swag@latest

1.2 安装air

使用的air库

go install github.com/cosmtrek/air@latests

2、安装本工具

go install github.com/Lyzin/gins-cli@latest

2.1 查看本工具帮助信息

gins-cli -h

3、创建项目

# 进去需要创建项目的目录
cd your-project-dir

# 创建项目,项目名就是项目的目录名以及go mod文件中的mod名,所以建议创建的时候规范一些,比如这样的:example.com/xx/xxx
gins-cli startproject you-project-name

4、运行项目

# 进入新创建的项目
cd your-new-project-dir

# 创建go mod文件
go mod init you-project-name

# 同步项目依赖
go mod tidy

# 启动项目
make run

5、查看项目效果

项目启动以后,浏览器打开http://127.0.0.1:8090/you-project-name/swagger/index.html,可看到有一个的示例接口,可以直接发起请求

gins-cli's People

Watchers

刘阳 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.