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