go-study/gomock/demo.go
2024-05-29 11:02:08 +08:00

12 lines
251 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package gomock
func GetUserName(us UserService, id int) (string, error) {
// 使用依赖注入进来的具体结构体方法通常为需要mock的方法
user, err := us.GetUser(id)
if err != nil {
return "", err
}
return user.Name, nil
}