Coder Social home page Coder Social logo

609412635 / gin-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from why444216978/gin-api

0.0 0.0 0.0 361 KB

基于 go-gin 开发的 api 框架,封装各种常用组件,包括配置、日志、DB、Redis、RabbitMQ、分布式链路追踪等,目的在于提高Go应用开发效率。

Dockerfile 0.28% Go 99.72%

gin-api's Introduction

gin-api

基于 go-gin 开发的 api 框架,封装各种常用组件
有疑问随时联系本人
QQ群:909211071
个人QQ:444216978
微信:AbleYu_

配置相关

基于三方组件viper,文件配置需放到main.go同级目录conf_xx下

app.toml:

AppName = "gin-api"
AppPort = 777

log.toml:

InfoFile = "./logs/info.log"
ErrorFile = "./logs/error.wf.log"
Level = "info"

test_mysql:

[master]
Host = "127.0.0.1"
Port = "3306"
User = "root"
Password = "123456"
DB = "test"
Charset = "utf8mb4"
MaxOpen = 8
MaxIdle = 4
ExecTimeout = 10000

[slave]
Host = "127.0.0.1"
Port = "3306"
User = "root"
Password = "123456"
DB = "test"
Charset = "utf8mb4"
MaxOpen = 8
MaxIdle = 4
ExecTimeout = 10000

default_redis.toml:

Host = "127.0.0.1"
Port = 6379
Auth = ""
DB = 0
ConnectTimeout = 1
ReadTimeout = 1
WriteTimeout = 1
MaxActive = 30
MaxIdle = 10
IsLog = true
ExecTimeout = 100000

jaeger.toml:

Host = "127.0.0.1"
Port = "6831"

运行

  1. 创建上述基础配置文件
  2. log配置中的目录确保本地存在且有写入权限
  3. go run main.go
[why@localhost] ~/Desktop/go/gin-api$go run main.go 
2020/12/20 17:44:43 load redis.json
2020/12/20 17:44:43 load mysql.json
2020/12/20 17:44:43 new test_dao
2020/12/20 17:44:43 new test_service
2020/12/20 17:44:43 load log.json
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

2020/12/20 17:44:43 load env.json
[GIN-debug] GET    /ping                     --> gin-api/controllers/ping.Ping (6 handlers)
[GIN-debug] GET    /test/rpc                 --> gin-api/controllers/opentracing.Rpc (6 handlers)
[GIN-debug] GET    /test/panic               --> gin-api/controllers/opentracing.Panic (6 handlers)
[GIN-debug] GET    /test/conn                --> gin-api/controllers/conn.Do (6 handlers)
2020/12/20 17:44:43 Actual pid is 9104

注意:测试 /test/conn 接口时,应确检查如下几项:

  1. mysql 和 redis 配置文件符合示例配置文件中的default(当然可以自定义,不过需要更改 test_model.go 和 goods_service.go 中的 DB_NAME )
  2. 创建 test 库
  3. 创建 test 表并随意插入数据
CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `goods_id` bigint(20) unsigned NOT NULL,
  `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `idx_goods` (`goods_id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin 

gin-api's People

Contributors

why444216978 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.