server

package
v0.0.0-...-ae01125 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRouter

func DefaultRouter() *fiber.App

func SendCode

func SendCode(ctx *fiber.Ctx, c code.Code) error

SendCode 返回任意 code

func SendDataCode

func SendDataCode[DATA any](ctx *fiber.Ctx, data DATA, c code.Code) error

SendDataCode 并返回数据,并指定 code

func SendDataOk

func SendDataOk[DATA any](ctx *fiber.Ctx, data DATA) error

SendDataOk 请求响应成功,并返回数据

func SendError

func SendError(ctx *fiber.Ctx, err error) error

SendError 根据 err 确定返回内容 如果 err 为 nil,则返回 Success 如果 err 为 *code.Error,则返回对应的 code 和 msg 如果 err 不为 nil,则返回 Failed

func SendFailed

func SendFailed(ctx *fiber.Ctx) error

SendFailed 请求失败

func SendJson

func SendJson(ctx *fiber.Ctx, data any) error

SendJson 返回 json 响应。用于收拢响应返回

func SendOk

func SendOk(ctx *fiber.Ctx) error

SendOk 请求响应成功

func SendPageDataOk

func SendPageDataOk[DATA any](ctx *fiber.Ctx, data DATA, page, pageSize int, total int64) error

SendPageDataOk 请求响应成功,并返回分页数据

func SendParamsParseFailed

func SendParamsParseFailed(ctx *fiber.Ctx, failedFields []*FailedField) error

SendParamsParseFailed 返回解析失败的字段信息

Types

type BasicResponse

type BasicResponse struct {
	Code code.Code `json:"code"` // 响应状态码
	Msg  string    `json:"msg"`  // 响应信息
}

BasicResponse 基础请求响应

type DataResponse

type DataResponse[DATA any] struct {
	BasicResponse
	Data DATA `json:"data"` // 响应数据
}

DataResponse 带响应数据响应

type FailedField

type FailedField struct {
	FailedField string `json:"failed_field"` // 异常字段
	Tag         string `json:"tag"`          // 验证 tag
	Value       string `json:"value"`        // 验证值
}

FailedField 验证失败字段

func Validate

func Validate[P any](params P) []*FailedField

Validate 验证参数

type PageResponse

type PageResponse[DATA any] struct {
	Page     int   `json:"page"`      // 当前页
	PageSize int   `json:"page_size"` // 每页大小
	Total    int64 `json:"total"`     // 总数
	Data     DATA  `json:"data"`      // 数据
}

PageResponse 分页查询内层响应

type ParamsParseFailedResponse

type ParamsParseFailedResponse struct {
	BasicResponse
	FailedFields []*FailedField `json:"failed_fields"` // 异常字段
}

ParamsParseFailedResponse 参数解析失败响应

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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