Golang界面:无法为未导出的字段分配值

I'm a new in golang, I try to mock some struct for unit testing and I use following site

我写了以下内容:

多尔

package user

import "errors"

type Doer interface {
    Do(int, string) error
}

type DoerImp struct {

}

func (d *DoerImp)Do(val int, str string) error{
    if val == 3{
        return errors.New("Some error")
    }
    return nil
}

用户

package user

type User struct {
    doer Doer
}

func (u *User) UseDoer() {
    u.doer.Do(1, "abc")
}

从主要我想运行以下代码:

c := &user.DoerImp{}
u := user.User{c}
u.UseDoer()

However I get an error: Cannot assign value to unexported field 'doer'

What I'm doing wrong?
my c value has Doer interface signature

评论