Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply 将 opts 应用在 t 之上
Example ¶
u := &User{} Apply[User](u, WithName("Tom"), WithAge(18)) fmt.Println(u)
Output: &{Tom 18}
func ApplyErr ¶
ApplyErr 形如 Apply,它将 opts 应用在 t 之上, 如果 opts 中任何一个返回 error,那么它会中断并且返回 error
Example ¶
u := &User{} err := ApplyErr[User](u, WithNameErr("Tom"), WithAgeErr(18)) fmt.Println(err) fmt.Println(u) err = ApplyErr[User](u, WithNameErr(""), WithAgeErr(18)) fmt.Println(err)
Output: <nil> &{Tom 18} name 不能为空
Types ¶
Click to show internal directories.
Click to hide internal directories.