Code Monkey home page Code Monkey logo

go-gin-api's Introduction

go-gin-api

基于 Gin 进行模块化设计的 API 框架,封装了常用的功能,使用简单,致力于进行快速的业务研发。

持续更新...

Features

  • 使用 go modules 初始化项目
  • 安装 Gin 框架
  • 性能分析工具(pprof)
  • 支持优雅地重启或停止
  • 规划项目目录
  • 参数验证(validator.v9)
    • 模型绑定和验证
    • 自定义验证器
  • 路由中间件
    • 签名验证
      • MD5 组合加密
      • AES 对称加密
      • RSA 非对称加密
    • 日志记录
    • 异常捕获
    • 链路追踪(Jaeger)
    • 限流
  • 自定义告警
    • 邮件(gomail)
    • 微信
    • 短信
    • 钉钉
  • 存储
    • MySQL
    • Redis
    • MongoDB
  • gRPC
  • ...

Download

git clone https://github.com/xinliangnote/go-gin-api.git

Quick start

Requirements

  • Go version >= 1.12
  • Global environment configure (Linux/Mac)
export GO111MODULE=on
export GOPROXY=https://goproxy.io

Build & Run

cd go-gin-api

go run main.go

输出如下,表示 Http Server 启动成功。
|-----------------------------------|
|            go-gin-api             |
|-----------------------------------|
|  Go Http Server Start Successful  |
|    Port:9999     Pid:xxxxx        |
|-----------------------------------|

HTTP Demo

curl -X POST http://127.0.0.1:9999/product

Jaeger Demo

访问:

http://127.0.0.1:9999/jaeger_test

服务端测试代码:

pprof

http://127.0.0.1:9999/debug/pprof

说明文档:

// 查看 CPU 信息
go tool pprof 127.0.0.1:9999/debug/pprof/profile
...
(pprof) 

//输入 web,生成 svg 文件。
//输入 png,生成 png 文件。
//输入 top,查看排名前 20 的信息。
//查看更多命令,请执行 pprof help。

其他同理,比如:

// 查看 内存 信息
go tool pprof 127.0.0.1:9999/debug/pprof/heap

// 查看 协程 信息
go tool pprof 127.0.0.1:9999/debug/pprof/goroutine

// 查看 锁 信息
go tool pprof 127.0.0.1:9999/debug/pprof/mutex

如果还想查看火焰图,请执行如下命令:

// 1.下载 pprof 工具
go get -u github.com/google/pprof

// 2.启动可视化界面
pprof -http=:9998 xxx.cpu.prof

// 3.查看可视化界面
http://127.0.0.1:9998/ui/

Dependence

  • WEB 框架:github.com/gin-gonic/gin
  • 链路追踪:github.com/jaegertracing/jaeger-client-go
  • 限流:golang.org/x/time/rate
  • 工具包:github.com/xinliangnote/go-util

Document

Learning together

go-gin-api's People

Contributors

xinliangnote avatar

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.