api

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEmptyDataStructNull   int = 0 //空(null)
	DefaultEmptyDataStructObject int = 1 //大(花)括号
	DefaultEmptyDataStructArray  int = 2 //中(方)括号
	DefaultEmptyDataStructString int = 3 //空字符串
)

Variables

This section is empty.

Functions

func SetupOption

func SetupOption(opt Option)

SetupOption 设置选项

目前支持设定:

1.成功code码及对应code信息

2.空数据序列化结构

Types

type API

type API struct {
	// contains filtered or unexported fields
}

func New

func New(c *gin.Context) API

func (API) Assemble

func (a API) Assemble(code constants.ICodeType, resp dto.IResponse, message ...string) API

Assemble 组装返回数据

该方法会根据传递的code码自动设置http状态、描述信息、当前系统毫秒时间戳以及请求id(需要在路由配置中调用middleware.Before中间件)

func (API) Send

func (a API) Send()

Send 响应请求

func (API) SendWithCode

func (a API) SendWithCode(httpCode int)

SendWithCode 以指定http状态码响应请求

func (API) Status

func (a API) Status(httpCode int) API

Status 指定http状态码

该方法会覆盖Assemble解析的http状态码值

type Option

type Option struct {
	//成功code码,默认成功code码为0,配置此项后,成功code码将使用这个值。
	ErrNoneCode constants.ICodeType
	//成功提示语,默认成功提示语为SUCCESS,配置此项后,成功提示语将使用这个值。
	ErrNoneCodeMsg string
	//空data序列化结构,默认返回的data字段为空时为null值,配置此项后,空data序列化格式将使用这个值。
	EmptyDataStruct int
	//强制使用200作为http的状态码,配置此项后,http状态码将不从业务code码中解析。
	//
	//注意,调用Status()方法和SendWithCode()方法时的优先级高于此项配置。
	ForceHttpCode200 bool
	//时区
	Timezone string
}

Option 配置项

Jump to

Keyboard shortcuts

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