controller

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	GinContext *gin.Context // 请求上下文
	Debug      bool         // 调试模式
}

func (Base) Failure

func (c Base) Failure(args ...any)

Failure 返回失败的响应 这个方法用于简化失败响应的构建,接收可变参数 并根据参数数量确定响应的data、message、code字段的值。 参数:

  • message string: 返回的消息内容
  • data any: 返回的数据
  • code int: 错误码

仅1个参数时,如果是字符串则作为message输出,否则作为data输出; 更多参数时,第一个参数为message,第二个参数为data,第三个参数为code;

func (Base) GetSafeMapGPC

func (c Base) GetSafeMapGPC(key ...string) (mapData map[string]any)

GetSafeMapGPC 安全获取map类型GPC

func (Base) Result

func (c Base) Result(code int, msg string, args ...any)

Result 整理结果输出 这个方法用于统一返回API响应结果。接收状态码、消息以及可选的额外参数, 并根据传入的数据类型对结果进行格式化和处理,最终返回JSON格式的响应。 参数:

  • code int: 状态码,通常为HTTP状态码。
  • msg string: 返回的消息内容。
  • data any 选填,主要数据内容,可以是结构体、map、string或slice。
  • additionalParams map[string]any 选填,附加参数

func (Base) Success

func (c Base) Success(args ...any)

Success 返回成功的响应 这个方法用于简化成功响应的构建,接收可变参数, 并根据参数数量确定响应的data、additionalParams和message字段的值。 参数:

  • message string: 返回的消息内容
  • data any: 返回的数据
  • additionalParams any: 附加数据

仅1个参数时,如果是字符串则作为message输出,否则作为data输出; 更多参数时,第一个参数为data,第二个参数为message,第三个参数为additionalParams;

Jump to

Keyboard shortcuts

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