resp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package resp provides a unified HTTP response format for Gin-based APIs.

Usage:

resp.Ok(c, user)
resp.Fail(c, 40101, "未登录")
resp.Page(c, list, total, page, size)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(c *gin.Context, err error)

Error sends a parameter binding error (code 40001).

func Fail

func Fail(c *gin.Context, code int, msg string)

Fail sends a business error response (HTTP 200, error in code field).

func Ok

func Ok(c *gin.Context, data ...any)

Ok sends a 200 success response with optional data.

func Page

func Page(c *gin.Context, list any, total int64, page, size int)

Page sends a paginated success response.

Types

type PageData

type PageData struct {
	List        any   `json:"list"`
	Total       int64 `json:"total"`
	PageSize    int   `json:"pageSize"`
	CurrentPage int   `json:"currentPage"`
}

PageData wraps paginated results.

type R

type R struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data,omitempty"`
}

R is the standard API response envelope.

Jump to

Keyboard shortcuts

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