1 Star 1 Fork 0

水不要鱼/errors

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
types.go 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
水不要鱼 提交于 2024-08-11 00:19 . 完善 args 格式化输出
// Copyright 2024 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package errors
const (
codeBadRequest = 400
codeForbidden = 403
codeNotFound = 404
codeRequireLogin = 1000
)
// BadRequest returns *Error with bad request code.
func BadRequest(message string, args ...any) *Error {
return Wrap(codeBadRequest, message, args...)
}
// Forbidden returns *Error with forbidden code.
func Forbidden(message string, args ...any) *Error {
return Wrap(codeForbidden, message, args...)
}
// NotFound returns *Error with not found code.
func NotFound(message string, args ...any) *Error {
return Wrap(codeNotFound, message, args...)
}
// RequireLogin returns *Error with require login code.
func RequireLogin(message string, args ...any) *Error {
return Wrap(codeRequireLogin, message, args...)
}
// MatchBadRequest matches err with bad request code.
func MatchBadRequest(err error) bool {
return Match(err, codeBadRequest)
}
// MatchForbidden matches err with forbidden code.
func MatchForbidden(err error) bool {
return Match(err, codeForbidden)
}
// MatchNotFound matches err with not found code.
func MatchNotFound(err error) bool {
return Match(err, codeNotFound)
}
// MatchRequireLogin matches err with require login code.
func MatchRequireLogin(err error) bool {
return Match(err, codeRequireLogin)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/FishGoddess/errors.git
git@gitee.com:FishGoddess/errors.git
FishGoddess
errors
errors
main

搜索帮助

0d507c66 1850385 C8b1a773 1850385