package main
import "fmt"
// import "errors"
// type CustomError struct {
// Code int `json:"code"` // 业务码
// Text string `json:"message"` // 描述信息
// }
// func (e *CustomError) Error() string {
// return e.Text
// }
var CustomErrors = map[int] string { 50: "算得上是", 10: "上是", 20: "算得是"}
type err int
func (e err) Error() string {
return CustomErrors[int(e)]
}
func (e err) Code() int {
return int(e)
}
func main() {
rc := err(50)
fmt.Println(errors.As(rc, error) )
rr := err(10)
fmt.Println(rr.Code(), rr.Error())
}
https://juejin.cn/post/7203341999956164664
https://juejin.cn/post/6920876156598091790
https://juejin.cn/post/6943786878780833806
https://zhuanlan.zhihu.com/p/84599497
https://zhuanlan.zhihu.com/p/380959953
https://juejin.cn/post/7027011560040038413
网友评论