api

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package api 提供api 相关的一些定义和工具函数

Index

Constants

View Source
const (
	ResultKey = "xinApiResult"
	//StatusKey context 中使用的api 返回 status key 名称
	StatusKey = "xinApiStatus"
	//ErrKey context 中使用的api 返回 error key  名称
	ErrKey = "xinApiErrorMsg"
	//DataKey context 中使用的api 实际返回业务数据的 key 名称
	DataKey = "xinApiData"
	//StatusDefault api handle 未定义status 时返回的默认成功值
	StatusDefault = 200
	//WrapperIndex 指定api 使用的wrapper 逻辑
	WrapperIndex = "xinWrapperIndex"
	//ErrorStatusDefault api handle 未定义status 时返回的默认失败值
	ErrorStatusDefault = 500
	//UserKey api 保存的用户对象的key
	UserKey = "xinUser"
	//JWTTokenKey context 中保存jwt-go token 对象的key
	JWTTokenKey = "xinJWTToken"
	//SessionKey context 中保存session 的 key
	SessionKey = "xinSession"

	//S shorcut of StatusKey
	S = StatusKey
	//E shortcut of ErrKey
	E = ErrKey
	//D shortcut of DataKey
	D = DataKey
	//U shortcut of UserKey
	U = UserKey
)

define key name used in context

Variables

This section is empty.

Functions

func CheckReqJSON

func CheckReqJSON(c *gin.Context, schemaStr string, obj interface{}) (bool, error)

CheckReqJSON 检查gin context 中的request body 是否是正确的json ,如果是,则将其解析到传入的结构体中并返回true 此函数需要配合responseRender 渲染中间键才会生效 如果json 不合法则会直接设置解析错误的内容,并返回false 和错误对象

Types

type Cache

type Cache struct {
	Status *int
	Data   interface{}
	Err    error
}

Cache response cache of an API Call

func SetData

func SetData(data interface{}) *Cache

SetData get an Cache with giving data

func SetError

func SetError(err error) *Cache

SetError get an Cache with giving error

func SetErrorf

func SetErrorf(format string, a ...interface{}) *Cache

SetErrorf get an Cache with error by giving format

func SetStatus

func SetStatus(code int) *Cache

SetStatus get an Cache with giving response body code

func (*Cache) Apply

func (ac *Cache) Apply(c *gin.Context)

Apply apply apiContext on given gin context ,this make the real change of an api call

func (*Cache) SetData

func (ac *Cache) SetData(data interface{}) *Cache

SetData set the response data of the Cache

func (*Cache) SetError

func (ac *Cache) SetError(err error) *Cache

SetError set the error of the Cache

func (*Cache) SetErrorf

func (ac *Cache) SetErrorf(format string, a ...interface{}) *Cache

SetErrorf set the error of the Cache by given string format

func (*Cache) SetStatus

func (ac *Cache) SetStatus(code int) *Cache

SetStatus set the response code of the Cache

Directories

Path Synopsis
Package middleware 自定义 api 中间键包,提供常用业务场景中会使用到的一些中间键封装 某些自定义功能可能会需要几个中间键组合在一起才能生效
Package middleware 自定义 api 中间键包,提供常用业务场景中会使用到的一些中间键封装 某些自定义功能可能会需要几个中间键组合在一起才能生效

Jump to

Keyboard shortcuts

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