Undefined (type []employee has no field or method name)

The example variable declaration below does not inherit the fields or methods from the struct.
How can this be reformulated to access fields within the struct while retaining the append. An example is below.
Thanks in advance.

package main

import "fmt"

type employee struct {
    name   string
    last string

func main() {
   emp := []employee{}
   emp = append(emp, employee{name: "Sam", last: "Fish"})
    fmt.Printf("name is: %s\n", emp.name)

emp.name undefined (type []employee has no field or method name)

emp is a slide and not a struct so you need and index to get access to the info inside it. So change, emp.name to emp[0].name

oh. Thank you.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.