Documentation
¶
Index ¶
- func AddContentEncoding(w http.ResponseWriter, encoding string)
- func BadRequest(w http.ResponseWriter, msg ...string)
- func CheckReqPost(w http.ResponseWriter, r *http.Request) bool
- func Copy(dst io.Writer, src io.Reader) (written int64, err error)
- func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)
- func Forbidden(w http.ResponseWriter, msg ...string)
- func FormDataDecodeResp[T any](w http.ResponseWriter, r *http.Request, sizes ...int64) (*T, bool)
- func InternalServerError(w http.ResponseWriter)
- func JsonDecodePtrResp[T interface{ ... }, E any](w http.ResponseWriter, r *http.Request) (T, bool)
- func JsonDecodeResp[T any](w http.ResponseWriter, r *http.Request) (T, bool)
- func MethodNotAllow(w http.ResponseWriter)
- func NotFound(w http.ResponseWriter, msg ...string)
- func ParseRequestBodyAsAnySliceAndLength(w http.ResponseWriter, r *http.Request) ([]any, int, error)
- func Play(path string, w http.ResponseWriter, r *http.Request, args ...any)
- func PostQueryFieldWithValidRegexp(w http.ResponseWriter, r *http.Request, field string, rule *regexp.Regexp) (string, bool)
- func QueryFieldWithValidRegexp(w http.ResponseWriter, r *http.Request, field string, rule *regexp.Regexp) (string, bool)
- func ReqError(r *http.Request, i ...any)
- func RespErrWithCode(w http.ResponseWriter, r *http.Request, respInfo RespCode, err error, d ...any)
- func RespJson(w http.ResponseWriter)
- func RespWithCode(w http.ResponseWriter, respInfo RespCode, d ...any)
- func SetDownloadBytes(w http.ResponseWriter, r *http.Request, b *[]byte, fileName string)
- func SetReturn(w http.ResponseWriter, code int, msg ...any)
- func SetReturnCheckErr(w http.ResponseWriter, r *http.Request, err error, code int, msg any, ...)
- func SetReturnCheckErrDisableLog(w http.ResponseWriter, r *http.Request, err error, code int, msg any, ...)
- func SetReturnCheckErrWithoutError(w http.ResponseWriter, r *http.Request, err error, code int, msg any, ...)
- func SetReturnCode(w http.ResponseWriter, r *http.Request, code int, msg any, data ...any)
- func SetReturnData(w http.ResponseWriter, code int, msg any, data ...any)
- func SetReturnError(w http.ResponseWriter, r *http.Request, err error, code int, msg ...any)
- func SetReturnErrorDisableLog(w http.ResponseWriter, err error, code int, msg ...any)
- func SetReturnFile(w http.ResponseWriter, r *http.Request, file string)
- func SetReturnWithoutError(w http.ResponseWriter, r *http.Request, err error, code int, msg ...any)
- func Status(w http.ResponseWriter, code int, msg ...string)
- func Unauthorized(w http.ResponseWriter, msg ...string)
- type DataList
- type RespCode
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 CopyBuffer ¶
CopyBuffer 复制数据,并自动刷新
func FormDataDecodeResp ¶
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 JsonDecodeResp ¶
func ParseRequestBodyAsAnySliceAndLength ¶
func ParseRequestBodyAsAnySliceAndLength(w http.ResponseWriter, r *http.Request) ([]any, int, error)
ParseRequestBodyAsAnySliceAndLength 解析请求体为any切片,同时获取请求体长度
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 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 ¶
SetDownloadBytes 下载来源是字节数组
func SetReturn ¶
func SetReturn(w http.ResponseWriter, code int, msg ...any)
SetReturn 设置 返回函数Play Deprecated: 请使用 SetReturnData
func SetReturnCheckErr ¶
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 ¶
SetReturnCode 设置返回函数 code值异常,会记录日志 Deprecated: 弃用,请使用 SetReturnData
func SetReturnData ¶
func SetReturnData(w http.ResponseWriter, code int, msg any, data ...any)
SetReturnData 设置返回函数 如果 code 异常,不想记录日志,就可以直接使用这个
func SetReturnError ¶
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 ¶
SetReturnWithoutError ,错误信息会记录下来,但是只会反馈msg
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, msg ...string)
Unauthorized 401 Unauthorized (建议新增)