response

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContentEncoding

func AddContentEncoding(w http.ResponseWriter, encoding string)

func BadRequest

func BadRequest(w http.ResponseWriter, msg ...string)

BadRequest 400 Bad Request (建议新增)

func CheckReqPost

func CheckReqPost(w http.ResponseWriter, r *http.Request) bool

CheckReqPost 检查请求是否post

func Copy

func Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy 复制数据,并自动刷新

func CopyBuffer

func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)

CopyBuffer 复制数据,并自动刷新

func Forbidden

func Forbidden(w http.ResponseWriter, msg ...string)

Forbidden 设置系统返回403

func FormDataDecodeResp

func FormDataDecodeResp[T any](w http.ResponseWriter, r *http.Request, sizes ...int64) (*T, bool)

FormDataDecodeResp 解析表单数据并将其解码为指定类型T的实例。 该函数控制上传内容的大小,并处理表单数据的解析。 参数:

w: http.ResponseWriter,用于写入HTTP响应。
r: *http.Request,包含HTTP请求的详细信息。
size: int64,允许的最大上传大小,单位为MB。

返回值:

T: 解析后的表单数据实例。
bool: 表单数据是否成功解析。

func InternalServerError

func InternalServerError(w http.ResponseWriter)

func JsonDecodePtrResp

func JsonDecodePtrResp[T interface{ *E }, E any](w http.ResponseWriter, r *http.Request) (T, bool)

func JsonDecodeResp

func JsonDecodeResp[T any](w http.ResponseWriter, r *http.Request) (T, bool)

func MethodNotAllow

func MethodNotAllow(w http.ResponseWriter)

MethodNotAllow 405

func NotFound

func NotFound(w http.ResponseWriter, msg ...string)

NotFound 设置返回 404

func ParseRequestBodyAsAnySliceAndLength

func ParseRequestBodyAsAnySliceAndLength(w http.ResponseWriter, r *http.Request) ([]any, int, error)

ParseRequestBodyAsAnySliceAndLength 解析请求体为any切片,同时获取请求体长度

func Play

func Play(path string, w http.ResponseWriter, r *http.Request, args ...any)

Play 公共函数文件 Deprecated: As of utils v1.1.0, this value is simply [router.Play].

func PostQueryFieldWithValidRegexp

func PostQueryFieldWithValidRegexp(w http.ResponseWriter, r *http.Request, field string, rule *regexp.Regexp) (string, bool)

PostQueryFieldWithValidRegexp 检查POST请求中的查询参数是否符合指定的正则表达式规则,并返回匹配结果。

func QueryFieldWithValidRegexp

func QueryFieldWithValidRegexp(w http.ResponseWriter, r *http.Request, field string, rule *regexp.Regexp) (string, bool)

QueryFieldWithValidRegexp 检查查询参数是否符合指定的正则表达式规则,并返回匹配结果。

func ReqError

func ReqError(r *http.Request, i ...any)

func RespErrWithCode

func RespErrWithCode(w http.ResponseWriter, r *http.Request, respInfo RespCode, err error, d ...any)

RespErrWithCode 根据业务上配置的错误码,进行数据响应

func RespJson

func RespJson(w http.ResponseWriter)

func RespWithCode

func RespWithCode(w http.ResponseWriter, respInfo RespCode, d ...any)

RespWithCode 根据业务上配置的响应码,进行数据响应

func SetDownloadBytes

func SetDownloadBytes(w http.ResponseWriter, r *http.Request, b *[]byte, fileName string)

SetDownloadBytes 下载来源是字节数组

func SetReturn

func SetReturn(w http.ResponseWriter, code int, msg ...any)

SetReturn 设置 返回函数Play Deprecated: 请使用 SetReturnData

func SetReturnCheckErr

func SetReturnCheckErr(w http.ResponseWriter, r *http.Request, err error, code int, msg any, data ...any)

func SetReturnCheckErrDisableLog

func SetReturnCheckErrDisableLog(w http.ResponseWriter, r *http.Request, err error, code int, msg any, data ...any)

SetReturnCheckErrDisableLog 设置响应数据,根据err判断响应内容, 并不记录日志

func SetReturnCheckErrWithoutError

func SetReturnCheckErrWithoutError(w http.ResponseWriter, r *http.Request, err error, code int, msg any, data ...any)

SetReturnCheckErrWithoutError 设置响应数据,根据err判断响应内容, 不响应err信息

func SetReturnCode

func SetReturnCode(w http.ResponseWriter, r *http.Request, code int, msg any, data ...any)

SetReturnCode 设置返回函数 code值异常,会记录日志 Deprecated: 弃用,请使用 SetReturnData

func SetReturnData

func SetReturnData(w http.ResponseWriter, code int, msg any, data ...any)

SetReturnData 设置返回函数 如果 code 异常,不想记录日志,就可以直接使用这个

func SetReturnError

func SetReturnError(w http.ResponseWriter, r *http.Request, err error, code int, msg ...any)

SetReturnError 错误信息会记录下来,同时也会反馈给前端

func SetReturnErrorDisableLog

func SetReturnErrorDisableLog(w http.ResponseWriter, err error, code int, msg ...any)

SetReturnErrorDisableLog 不记录日志,err 变量忽略不处理

func SetReturnFile

func SetReturnFile(w http.ResponseWriter, r *http.Request, file string)

SetReturnFile 直接讲文件反馈给前端

func SetReturnWithoutError

func SetReturnWithoutError(w http.ResponseWriter, r *http.Request, err error, code int, msg ...any)

SetReturnWithoutError ,错误信息会记录下来,但是只会反馈msg

func Status

func Status(w http.ResponseWriter, code int, msg ...string)

func Unauthorized

func Unauthorized(w http.ResponseWriter, msg ...string)

Unauthorized 401 Unauthorized (建议新增)

Types

type DataList

type DataList[T any] struct {
	List  []*T  `json:"list"`
	Total int64 `json:"total"`
}

type RespCode

type RespCode interface {
	HttpCode() int   // 设置 http 响应状态码
	RespCode() int   // 设置业务响应码
	Message() string // 设置业务响应信息
	EnableLog() bool // 是否记录日志

}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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