今天给大家说一说go语言接口做参数示例,话不多说直接上代码:
type IUserService interface {
GenId()
}
type UserService struct {
id string
}
func (u *UserService) GenId() {
generateUUID, _ := uuid.GenerateUUID()
u.id = generateUUID
}
func BuildUser(service IUserService) {
service.GenId()
}
func main() {
userService := UserService{}
BuildUser(&userService)
//BuildUser(userService) *UserService实现了IUserService,UserService没有实现IUserService
println(userService.id)
}
以上便是go语言接口做参数示例的全部内容,更多内容可关注慕课网其他文章~