packagemainimport"bank"funcmain() {var x =&bank.Account{ UserID: 1, // this works fine accessToken: "one", // this does not work, since accessToken is unexported }}
不过,在bank包中,您访问UserID或accessToken都没问题。
bank包的实现如下:
packagebanktypeAccountstruct { UserID int accessToken string}funcProcessUser(u *Account) {// ProcessUser() can access u.accessToken because// it's defined in the same package u.accessToken =doSomething(u)}