今天给大家说一说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语言接口做参数示例的全部内容,更多内容可关注慕课网其他文章~
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦