resp

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fail

func Fail(w http.ResponseWriter, r *http.Request, code int, args ...any)

Fail 失败响应 (chi 框架)

func Ok

func Ok(w http.ResponseWriter, r *http.Request, args ...any)

Ok 成功响应 (chi 框架)

func Out

func Out(w http.ResponseWriter, r *http.Request, code int, args ...any)

Out 响应输出

Types

type CoderMessager

type CoderMessager interface {
	Code() int
	GetMessage(r *http.Request) string
}

CoderMessager get message and code with http request

type Done

type Done struct {
	Code   int   `json:"status" example:"0"` // 状态值,0=ok
	Time   int64 `json:"t,omitempty"`        // 时间戳
	Result any   `json:"result,omitempty"`   // 主体数据,可选
	Extra  any   `json:"extra,omitempty"`    // 附加数据,可选
}

Done 操作成功返回的结构

type Error

type Error struct {
	Code    int    `json:"status" example:"1"`             // 错误代码,可选
	Message string `json:"message" example:"错误信息"`         // 错误信息
	Field   string `json:"field,omitempty" example:"错误字段"` // 错误字段,可选,多用于表单校验
}

Error ...

func GetError

func GetError(r *http.Request, code int, err any, args ...any) Error

GetError ...

type Failure

type Failure struct {
	Code    int    `json:"status" example:"1"`             // 状态值
	Time    int64  `json:"t,omitempty"`                    // 时间戳
	Message string `json:"message" example:"错误信息"`         // 错误信息
	Field   string `json:"field,omitempty" example:"错误字段"` // 错误字段,可选,多用于表单校验
}

Failure 出现错误,返回相关的错误码和消息文本

type FieldError

type FieldError interface {
	error
	Field() string
}

FieldError a error with field, for validator

type FieldMessager

type FieldMessager interface {
	Field() string
	GetMessage(r *http.Request) string
}

FieldMessager a error with field

type Messager

type Messager interface {
	GetMessage(r *http.Request) string
}

Messager get message with http request

type ResultData

type ResultData struct {
	Data  any `json:"data,omitempty"`  // 数据集数组
	Total int `json:"total,omitempty"` // 符合条件的总记录数
}

ResultData 特定数据集(带JSON数组和总数),一般用在分页查询结果

func (*ResultData) PatchView

func (dr *ResultData) PatchView()

type ResultID

type ResultID struct {
	ID any `json:"id"` // 主键值,多数时候是字串
}

type ResultOk

type ResultOk struct {
	Ok bool `json:"ok"`
}

type ViewPatcher

type ViewPatcher interface {
	PatchView()
}

ViewPatcher 视图修补接口

Jump to

Keyboard shortcuts

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