1. Error
package main import "fmt" type Error struct { errCode uint8 } func (e *Error) Error() string { switch e.errCode { case 1: return "file not found" case 2: return "time out" default: return "unknown error" } } func main() { err := new(Error) err.errCode = 2 msg := err.Error() fmt.Println(msg) }
有疑问加站长微信联系(非本文作者)