response

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

response 基于gin的Context,实现响应数据结构体 集成全局traceID

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data map[string]interface{}

数据对象

type ErrorItem

type ErrorItem struct {
	Key   string `json:"key"`
	Value string `json:"error"`
}

ErrorItem 错误项

func NewErrorItem

func NewErrorItem(key, msg string) ErrorItem

type ErrorItems

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

ErrorItems 错误项

func (ErrorItems) GetItems

func (e ErrorItems) GetItems() []ErrorItem

GetItems 获取错误项

func (*ErrorItems) IsEmpty

func (e *ErrorItems) IsEmpty() bool

IsEmpty 查看错误项是否为空

func (*ErrorItems) Push

func (e *ErrorItems) Push(key, msg string)

Push 添加错误项

type IResponse

type IResponse interface {
}

type Meta

type Meta struct {
	Trace      Trace                 `json:"trace"`
	Pagination *pagination.Paginator `json:"pagination"` // 分页信息
}

Meta 元数据

type Response

type Response struct {
	StatusCode interface{} `json:"status_code"` // 兼容字符串与int
	Message    string      `json:"message"`
	Data       interface{} `json:"data"`
	Meta       Meta        `json:"meta"`
	Errors     []ErrorItem `json:"errors"`
}

Response 数据结构体

func Decode

func Decode(result string) *Response

Decode 解析json数据Response

func New

func New() *Response

New return response instance

func (*Response) IsSuccess

func (response *Response) IsSuccess() bool

IsSuccess get response status

func (*Response) String

func (response *Response) String() string

String stringify response

type Trace

type Trace struct {
	TraceId   string `json:"trace_id"`   // 全局唯一Code
	RequestId string `json:"request_id"` // 当前请求code
}

Trace 跟踪信息

type Wrapper

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

Wrapper include context

func WrapContext

func WrapContext(ctx *gin.Context) *Wrapper

WrapContext

func (*Wrapper) Error

func (wrapper *Wrapper) Error(statusCode int, message string)

Error 错误输出

func (*Wrapper) Json

func (wrapper *Wrapper) Json(response IResponse)

Json 输出json,支持自定义response结构体

func (*Wrapper) Paginate

func (wrapper *Wrapper) Paginate(data interface{}, paginate *pagination.Paginator, formatMap bool)

Paginate 分页输出 formatMap 是否将data项格式化为数组

func (*Wrapper) Success

func (wrapper *Wrapper) Success(data interface{})

Success 成功的输出

Jump to

Keyboard shortcuts

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