zdpgo_api

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 1 Imported by: 0

README

zdpgo_api

基于gin二次封装的一个后端api快速开发框架

项目地址:https://github.com/zhangdapeng520/zdpgo_api

功能清单

  • 根据MySQL数据库表自动生成REST风格的CRUD API接口

版本历史

  • 版本1.0.0:2022年2月9日
  • 版本1.0.1:2022年2月11日 指定默认模板目录template和默认静态文件夹目录static
  • 版本1.0.2:2022年2月11日 移除本地依赖
  • 版本1.0.3:2022年2月11日 新增日志中间件和recover中间件
  • 版本1.0.4:2022年3月8日 优化模板和静态目录
  • 版本1.0.5:2022年3月8日 增加常用的统一返回对象
  • 版本1.0.6:2022年3月8日 将挂载通用路由设置为开关量
  • 版本1.0.7:2022年3月10日 支持配置服务相关参数
  • 版本1.0.8:2022年3月10日 支持viper读取和设置配置
  • 版本1.0.9:2022年3月11日 logger日志支持配置
  • 版本1.1.0:2022年3月12日 修复日志不打印body
  • 版本1.1.1:2022年4月8日 新增详细日志
  • 版本1.1.2:2022年4月8日 详细日志升级,支持查看的具体Body中的JSON数据

示例

根据MySQL数据库表自动生成REST风格的CRUD API接口

会自动生成以下接口:

  • 根据ID查询数据
  • 新增数据
  • 批量新增数据
  • 根据ID修改数据
  • 根据ID列表修改数据
  • 根据ID删除数据
  • 根据ID列表删除数据
  • 根据ID列表查询数据
  • 根据分页查询数据
package main

import (
	"github.com/zhangdapeng520/zdpgo_api/libs/gin"
	"github.com/zhangdapeng520/zdpgo_api"
	"github.com/zhangdapeng520/zdpgo_mysql"
)

type Student struct {
	Id     int64  `json:"id"`
	Name   string `json:"name"`
	Age    int    `json:"age"`
	Gender bool   `json:"gender"`
}

func main() {
	// 创建核心对象
	g := zdpgo_api.New(zdpgo_api.GinConfig{
		Debug: true,
	})

	// 设置MySQL
	g.SetMysql(zdpgo_mysql.MysqlConfig{
		Debug:    true,
		Host:     "192.168.33.101",
		Port:     3306,
		Username: "root",
		Password: "root",
		Database: "test",
	})

	// 创建app
	app := gin.Default()

	// 创建路由组
	group := app.Group("/api/v1")

	// 注册路由
	var students []Student
	g.RegisterCrudRouter(group, "student", &students)

	// 启动app
	app.Run("0.0.0.0:8888")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGinWithLog

func NewGinWithLog(isDetailLogger bool) *gin.Engine

NewGinWithLog 根据是否使用详细日志创建Gin的实例 @param isDetailLogger 是否使用详细日志,开启后,会记录请求头,form,body的详细信息

Types

This section is empty.

Directories

Path Synopsis
core
examples
gin/z01_basic command
gin/z06_grpc/pb
Package helloworld is a generated protocol buffer package.
Package helloworld is a generated protocol buffer package.
gin/z07_http2 command
libs
gin
Package gin implements a HTTP web framework called gin.
Package gin implements a HTTP web framework called gin.
sse
validator
Package validator implements value validations for structs and individual fields based on tags.
Package validator implements value validations for structs and individual fields based on tags.
yaml
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL