19 lines
364 B
Go
19 lines
364 B
Go
package httpx
|
|
|
|
import "fmt"
|
|
|
|
// CodeMsg 包含 code 与 msg 的错误结构,实现了 error 接口。
|
|
type CodeMsg struct {
|
|
Code int
|
|
Msg string
|
|
}
|
|
|
|
func (c *CodeMsg) Error() string {
|
|
return fmt.Sprintf("code: %d, msg: %s", c.Code, c.Msg)
|
|
}
|
|
|
|
// New 创建一个 CodeMsg 错误。
|
|
func New(code int, msg string) error {
|
|
return &CodeMsg{Code: code, Msg: msg}
|
|
}
|