add gcode.WithCode

This commit is contained in:
John Guo 2022-01-10 22:58:29 +08:00
parent 280c3b4a86
commit 0f67559995

View File

@ -57,3 +57,13 @@ func New(code int, message string, detail interface{}) Code {
detail: detail,
}
}
// WithCode creates and returns a new error code based on given Code.
// The code and message is from given `code`, but the detail if from given `detail`.
func WithCode(code Code, detail interface{}) Code {
return localCode{
code: code.Code(),
message: code.Message(),
detail: detail,
}
}