Accessing the struct field

Hi! Help me please

type employee struct {
    name    string
    age     int
    salary  int
    address address
}
 emp := employee{name: "Sam", age: 31, salary: 2000, address: address}

Can I get the value of employee something like this emp[“name”] or only emp.name?

Only as emp.name. There are ways you can get emp["name"] to work, but it requires more code, effort, setup, etc… It depends on why you want emp["name"] to work.

1 Like