我正在尝试使用go-errors来包含我生成的错误的堆栈跟踪。我有一个自定义HttpError类型,我也想包含堆栈跟踪。我最初的想法是用嵌入来做到这一点,但我似乎无法嵌入它,因为类 ( Error) 的名称与其中一个方法的名称相同。
package netutil
import (
"github.com/go-errors/errors"
)
type HttpError struct {
status int
*errors.Error
}
func (h *HttpError) Error() string {
return "Failed"
}
func NewHttpError(status int, message string) *HttpError {
return &HttpError{
status,
errors.New(message),
}
}
我收到以下错误:
tmp_error.go:12: type HttpError has both field and method named Error
有什么建议?
相关分类