controller

package
v0.0.0-...-42cc2d4 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseController

type BaseController struct {
	GCtx *gin.Context
	Response
	Request
}

func NewBaseController

func NewBaseController(ctx *gin.Context) BaseController

type Request

type Request struct {
	GCtx *gin.Context
	Val  string
}

func NewRequest

func NewRequest(ctx *gin.Context) Request

func (Request) Bool

func (req Request) Bool() bool

func (Request) GetAllParamsFromUrl

func (req Request) GetAllParamsFromUrl() map[string]string

GetAllParamsFromUrl 获取url中所有参数, 不支持数组

func (Request) GetHeader

func (req Request) GetHeader(key string) Request

GetHeader 获取响应头

func (Request) GetQuery

func (req Request) GetQuery(key string) Request

func (Request) GetQueryDefault

func (req Request) GetQueryDefault(key string, defaultValue string) Request

func (Request) GetValidMsg

func (req Request) GetValidMsg(err error, obj interface{}) string

GetValidMsg 参数校验

func (Request) IsMimeJson

func (req Request) IsMimeJson() bool

func (Request) PostForm

func (req Request) PostForm(key string) Request

func (Request) PostToModel

func (req Request) PostToModel(obj any) Request

func (Request) ShouldBindJSON

func (req Request) ShouldBindJSON(obj any)

ShouldBindJSON 使用注意,只能获取一次,无法重复获取 ShouldBindWith for better performance if you need to call only once.

func (Request) ShouldBindQuery

func (req Request) ShouldBindQuery(obj any) error

func (Request) Value

func (req Request) Value() string

type ResJson

type ResJson struct {
	Code    int32       `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

ResJson 响应的数据结构

type Response

type Response struct {
	GCtx *gin.Context
}

func NewResponse

func NewResponse(ctx *gin.Context) Response

func (Response) Fail

func (res Response) Fail(code int32, errMsg string)

func (Response) Fail400

func (res Response) Fail400(errMsg string)

func (Response) FailAbnormal

func (res Response) FailAbnormal()

FailAbnormal 服务器异常

func (Response) FailRefuse

func (res Response) FailRefuse()

FailRefuse 请求拒绝

func (Response) NilToArray

func (res Response) NilToArray(values interface{}) interface{}

NilToArray nil判断,如果是nil 返回空数组

func (Response) NilToObj

func (res Response) NilToObj(value interface{}) interface{}

NilToObj nil判断,如果是nil 返回空对象

func (Response) ResJson

func (res Response) ResJson(resJson ResJson)

func (Response) SetHeader

func (res Response) SetHeader(name string, val string)

SetHeader 设置响应头

func (Response) SetSrvHeader

func (res Response) SetSrvHeader()

SetSrvHeader 设置golang服务器独有请求头,区分PHP/Golang

func (Response) Success

func (res Response) Success(data interface{})

func (Response) SuccessWithMsg

func (res Response) SuccessWithMsg(data interface{}, msg string)

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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