type UserProxy struct{ User mobileProxyPractice.User } func NewUserProxy(User mobileProxyPractice.User)*UserProxy{ return &UserProxy{ User:User, } } func(this *UserProxy)Login(name string,passwd string)error{ time:=time.Now() //todo 他这个确实是功能增强的感觉 不过应用场景和立意不一样 this.User.Login(name,passwd) elaspe :=time.Sub(time) fmt.Println(elaspe) return nil }
——————————————————————————————————————————————————
package mobileProxyPractice import "fmt" type UserI interface { Login(name string,passwd string)error } type User struct { //SetParameter() Name string Passwd string } //SetParameter() func (this *User)SetParameter(name string,passwd string){ this.Name=name this.Passwd=passwd } func (this *User)Login(name string,passwd string)error{ // TODO 这个逻辑就是根据name从数据库表中找出密码 再去对比一下 密码和Input的摩玛是否一致 fmt.Println("do user login logic...........") return nil }
——————————————————————————————————————————————————
func TestEventFactory(t *testing.T) { //user:=mobileProxyPracticeRelative.UserProxy{} userProxy:=mobileProxyPracticeRelative.NewUserProxy(mobileProxyPractice.User{}) //user.User=&mobileProxyPractice.User{} err:=userProxy.Login("dali","123456") if err!=nil{ } }