Ai
1 Star 0 Fork 0

s-dy/yogurt

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
types.go 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
s-dy 提交于 2022-10-22 19:04 +08:00 . config,encoding, transport
package errors
import "net/http"
func BadRequest(reason, message string) *Error {
return New(http.StatusBadRequest, reason, message)
}
func IsBadRequest(err error) bool {
return Code(err) == http.StatusBadRequest // 400
}
func Unauthorized(reason, message string) *Error {
return New(http.StatusUnauthorized, reason, message)
}
func IsUnauthorized(err error) bool {
return Code(err) == http.StatusUnauthorized // 401
}
func Forbidden(reason, message string) *Error {
return New(http.StatusForbidden, reason, message)
}
func IsForbidden(err error) bool {
return Code(err) == http.StatusForbidden // 403
}
func NotFound(reason, message string) *Error {
return New(http.StatusNotFound, reason, message)
}
func IsNotFound(err error) bool {
return Code(err) == http.StatusNotFound // 404
}
func Conflict(reason, message string) *Error {
return New(http.StatusConflict, reason, message)
}
func IsConflict(err error) bool {
return Code(err) == http.StatusConflict // 409
}
func InternalServer(reason, message string) *Error {
return New(http.StatusInternalServerError, reason, message)
}
func IsInternalServer(err error) bool {
return Code(err) == http.StatusInternalServerError // 500
}
func ServiceUnavailable(reason, message string) *Error {
return New(http.StatusServiceUnavailable, reason, message)
}
func IsServiceUnavailable(err error) bool {
return Code(err) == http.StatusServiceUnavailable // 503
}
func GatewayTimeout(reason, message string) *Error {
return New(http.StatusGatewayTimeout, reason, message)
}
func IsGatewayTimeout(err error) bool {
return Code(err) == http.StatusGatewayTimeout // 504
}
func ClientClosed(reason, message string) *Error {
return New(499, reason, message) // 非http标准
}
func IsClientClosed(err error) bool {
return Code(err) == 499 // 非http标准
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdynasty/yogurt.git
git@gitee.com:sdynasty/yogurt.git
sdynasty
yogurt
yogurt
01d4da0b550e

搜索帮助