zdpgo_api

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 25 Imported by: 0

README

zdpgo_api

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

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

版本历史

  • v1.0.0 2022/02/09
  • v1.0.1 2022/02/11 指定默认模板目录template和默认静态文件夹目录static
  • v1.0.2 2022/02/11 移除本地依赖
  • v1.0.3 2022/02/11 新增日志中间件和recover中间件
  • v1.0.4 2022/03/08 优化模板和静态目录
  • v1.0.5 2022/03/08 增加常用的统一返回对象
  • v1.0.6 2022/03/08 将挂载通用路由设置为开关量
  • v1.0.7 2022/03/10 支持配置服务相关参数
  • v1.0.8 2022/03/10 支持viper读取和设置配置
  • v1.0.9 2022/03/11 logger日志支持配置
  • v1.1.0 2022/03/12 修复日志不打印body
  • v1.1.1 2022/04/08 新增详细日志
  • v1.1.2 2022/04/11 详细日志升级,支持查看的具体Body中的JSON数据
  • v1.1.3 2022/04/21 文件上传
  • v1.1.4 2022/05/16 新增:Api核心对象
  • v1.1.5 2022/05/17 优化:日志中间件优化
  • v1.1.6 2022/05/17 新增:添加静态文件服务
  • v1.1.7 2022/05/17 新增:API分组
  • v1.1.8 2022/06/06 新增:读取ECC加密的JSON数据
  • v1.1.9 2022/06/11 新增:读取ECC加密的文本数据
  • v1.2.0 2022/06/11 新增:读取AES加密的数据
  • v1.2.1 2022/06/14 优化:上传文件接口优化
  • v1.2.2 2022/06/15 优化:日志优化
  • v1.2.3 2022/06/20 优化:日志优化

Documentation

Index

Constants

View Source
const (
	AuthUserKey = "user" // 是基本身份验证中用户凭据的cookie名称。
)

Variables

Functions

func SetLog added in v1.2.2

func SetLog(log *zdpgo_log.Log)

SetLog 设置日志

Types

type Api added in v1.1.4

type Api struct {
	Config *Config     // 配置对象
	App    *gin.Engine // 核心App对象
}

Api API核心对象

func New added in v1.1.4

func New(log *zdpgo_log.Log) *Api

New 使用默认配置创建API

func NewWithConfig added in v1.1.4

func NewWithConfig(config *Config, log *zdpgo_log.Log) *Api

NewWithConfig 根据配置创建API

func (*Api) AddCorsMiddleware added in v1.1.4

func (a *Api) AddCorsMiddleware()

AddCorsMiddleware 添加跨域中间件

func (*Api) AddStaticFSRouter added in v1.1.6

func (a *Api) AddStaticFSRouter(routerPath string, fsObj fs.FS)

AddStaticFSRouter 添加嵌入式文件系统作为静态目录

func (*Api) AddStaticRouter added in v1.1.6

func (a *Api) AddStaticRouter(routerPath string, dirPath string)

AddStaticRouter 添加静态文件目录

func (*Api) AddUploadRouter added in v1.1.4

func (a *Api) AddUploadRouter(
	routerPath string,
	fileName string,
	saveDir string,
	handleResultList ...func(c *Context, file *multipart.FileHeader, err error))

AddUploadRouter 添加文件上传路由 @param routerPath 路由路径,比如:/upload @param fileName 上传文件的表单名称,比如:file @param saveDir 文件的上传路径,比如:./uploads @param handleResultList 处理结果的方法列表,用户可以自定义文件上传后的返回内容,处理错误信息

func (*Api) Any added in v1.1.7

func (a *Api) Any(method, routerPath string, handleFuncList ...func(ctx *Context))

Any 处理任意方法类型

func (*Api) CreateDirs added in v1.1.4

func (a *Api) CreateDirs(filePath string) error

CreateDirs 调用os.MkdirAll递归创建文件夹

func (*Api) Delete added in v1.1.7

func (a *Api) Delete(routerPath string, handleFuncList ...func(ctx *Context))

Delete 处理DELETE方法类型

func (*Api) Get added in v1.1.7

func (a *Api) Get(routerPath string, handleFuncList ...func(ctx *Context))

Get 处理GET方法类型

func (*Api) GetBasicAuthGroup added in v1.1.4

func (a *Api) GetBasicAuthGroup(routerPath string, accounts StringMap) (group *ApiGroup)

GetBasicAuthGroup 获取基本权限校验路由组

func (*Api) GetMd5 added in v1.2.1

func (a *Api) GetMd5(data string) string

GetMd5 获取MD5值

func (*Api) InitValidator added in v1.1.4

func (a *Api) InitValidator() (err error)

InitValidator 初始化校验器

func (*Api) IsExists added in v1.1.4

func (a *Api) IsExists(path string) bool

IsExists 判断所给路径文件/文件夹是否存在(返回true是存在)

func (*Api) Patch added in v1.1.7

func (a *Api) Patch(routerPath string, handleFuncList ...func(ctx *Context))

Patch 处理PATCH方法类型

func (*Api) Post added in v1.1.7

func (a *Api) Post(routerPath string, handleFuncList ...func(ctx *Context))

Post 处理POST方法类型

func (*Api) Put added in v1.1.7

func (a *Api) Put(routerPath string, handleFuncList ...func(ctx *Context))

Put 处理PUT方法类型

func (*Api) Run added in v1.1.4

func (a *Api) Run(exitFuncList ...func())

TODO: 自动重启https://www.codeleading.com/article/97834445692/ Run 运行APP

func (*Api) SetApp added in v1.1.4

func (a *Api) SetApp(app *gin.Engine)

SetApp 设置APP

func (*Api) SetLog added in v1.2.2

func (a *Api) SetLog(log *zdpgo_log.Log)

SetLog 设置日志

func (*Api) Validate added in v1.1.4

func (a *Api) Validate(data interface{}) (errData map[string]string)

Validate 校验结构体

type ApiGroup added in v1.1.7

type ApiGroup struct {
	gin.RouterGroup
}

ApiGroup API分组

func (*ApiGroup) Any added in v1.1.7

func (g *ApiGroup) Any(method, routerPath string, handleFuncList ...func(ctx *Context))

func (*ApiGroup) Delete added in v1.1.7

func (g *ApiGroup) Delete(routerPath string, handleFuncList ...func(ctx *Context))

Delete 处理DELETE方法类型

func (*ApiGroup) Get added in v1.1.7

func (g *ApiGroup) Get(routerPath string, handleFuncList ...func(ctx *Context))

Get 处理GET方法类型

func (*ApiGroup) Patch added in v1.1.7

func (g *ApiGroup) Patch(routerPath string, handleFuncList ...func(ctx *Context))

Patch 处理PATCH方法类型

func (*ApiGroup) Post added in v1.1.7

func (g *ApiGroup) Post(routerPath string, handleFuncList ...func(ctx *Context))

Post 处理POST方法类型

func (*ApiGroup) Put added in v1.1.7

func (g *ApiGroup) Put(routerPath string, handleFuncList ...func(ctx *Context))

Put 处理PUT方法类型

type Config added in v1.1.4

type Config struct {
	Debug          bool      `yaml:"debug" json:"debug"`
	Host           string    `yaml:"host" json:"host"`                         // 启动地址,默认0.0.0.0
	Port           int       `yaml:"port" json:"port"`                         // 启动端口号,默认3333
	UploadFileSize int64     `yaml:"upload_file_size" json:"upload_file_size"` // 上传文件大小限制(M),默认33
	Ecc            EccConfig `yaml:"ecc" json:"ecc"`
}

type Context added in v1.1.7

type Context struct {
	gin.Context
}

Context 重命名gin上下文

func (*Context) GetAesTextBodyToJson added in v1.2.0

func (c *Context) GetAesTextBodyToJson(jsonData interface{}) error

func (*Context) GetBody added in v1.1.8

func (c *Context) GetBody() ([]byte, error)

GetBody 获取body中的字符串数据

func (*Context) GetEccBodyToJson added in v1.1.8

func (c *Context) GetEccBodyToJson(jsonData interface{}) error

GetEccBodyToJson 读取ECC加密的内容并解析为JSON数据

func (*Context) GetEccTextBodyToJson added in v1.1.9

func (c *Context) GetEccTextBodyToJson(jsonData interface{}) error

func (*Context) GetResponseSuccess added in v1.2.1

func (c *Context) GetResponseSuccess(data interface{}) Response

获取成功的响应

func (*Context) ResponseAesStr added in v1.2.0

func (c *Context) ResponseAesStr(jsonResponse interface{})

func (*Context) ResponseEccStr added in v1.1.9

func (c *Context) ResponseEccStr(api *Api, jsonResponse interface{})

type EccConfig added in v1.1.8

type EccConfig struct {
	PrivateKey []byte `yaml:"private_key" json:"private_key"`
	PublicKey  []byte `yaml:"public_key" json:"public_key"`
}

type JsonMap added in v1.1.7

type JsonMap map[string]interface{}

JsonMap json字典类型

type Response added in v1.1.8

type Response struct {
	Code   int         `json:"code"`
	Msg    string      `json:"msg"`
	Status bool        `json:"status"`
	Data   interface{} `json:"data"`
}

type StringMap added in v1.1.7

type StringMap map[string]string

StringMap 字符串类型的字典

Directories

Path Synopsis
core
examples
grpc/api command
grpc/grpc command
grpc/pb
Package helloworld is a generated protocol buffer package.
Package helloworld is a generated protocol buffer package.
post_aes command
post_ecc command
post_ecctext command
validator command
gin
Package api implements a HTTP web framework called api.
Package api implements a HTTP web framework called api.
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.
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