error 小咪咪 2022-11-03 05:48 97阅读 0赞 fmt.Println 打印结构体的时候,会把其中的 error 的返回的信息打印出来。 type User struct { username string password string } func (p *User) init(username string ,password string) (*User,string) { if ""==username || ""==password { return p,p.Error() } p.username = username p.password = password return p,""} func (p *User) Error() string { return "Usernam or password shouldn't be empty!" } func main() { var user User user1, _ :=user.init("",""); fmt.Println(user1) } ![2021022710324760.png][] [2021022710324760.png]: /images/20221024/dbce36e5bda74906b1fccb6613792e67.png
还没有评论,来说两句吧...