api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorBusy       string = "系统繁忙,请稍后再试"
	ErrorMissUserId string = "缺少用户ID"
	ErrorForbidden  string = "当前账号没有操作权限"
)

错误消息内容

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code int

Code 响应码

const (
	CodeOk   Code = 200 // 成功
	CodeFail Code = 0   // 业务错误
)

业务接口响应码

const (
	CodeBadRequest          Code = 400 // 请求出错
	CodeUnauthorized        Code = 401 // 未授权
	CodeForbidden           Code = 403 // 无权限
	CodeNotFound            Code = 404 // 未找到
	CodeMethodNotAllowed    Code = 405 // 请求方法不允许
	CodeInternalServerError Code = 500 // 服务器内部错误
)

系统异常接口响应码

func (Code) ToInt

func (c Code) ToInt() int

func (Code) ToInt64

func (c Code) ToInt64() int64

type Record

type Record[T any] struct {
	Record T     `json:"record"`
	Total  int64 `json:"total"`
}

Record 分页列表记录结构

type Response

type Response[T any] struct {
	// Code 错误码
	Code Code `json:"code"`
	// Data data payload
	Data T `json:"data"`
	// Message 错误信息
	Message string `json:"message"`
	// TraceID 追踪id
	TraceID string `json:"trace_id"`
}

Response api 响应数据结构

func Fail

func Fail(ctx context.Context, message string, code Code) Response[any]

Fail 失败响应

func Success

func Success[T any](ctx context.Context, result T) Response[T]

Success 正确响应

Jump to

Keyboard shortcuts

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