GO自定义Error方法 Posted on 2020-12-27 Edited on 2024-06-04 In GO Word count in article: 337 Reading time ≈ 1 mins. 解析go语言,自定义error的方法,用于业务使用 通过interface定义 123type error interface { Error() string} 自定义error 123456789101112131415type Error struct { errCode uint8}func (e *Error) Error() string { switch e.errCode { case 1: return "file not found" case 2: return "time out" case 3: return "permission denied" default: return "unknown error" }}