golang filling a string array model


I cant figure out a way to fill the array string of the below simple model. What I have tried is also give. How do I fill the array string "Alternate"?

func main() {
    type Person struct {
        FirstName string   `json:"FirstName,omitempty"`
        LastName  string   `json:"Lastname,omitempty"`
        Age       string   `json:"Age,omitempty"`
        Alternate []string `json:"Alternate,omitempty"`

    p1 := Person{FirstName: "Rajeev", LastName: "Singh", Age: "27", Alternate: ["Samantha Holder"]}



Use a composite literal.

p1 := Person{
    FirstName: "Rajeev",
    LastName:  "Singh",
    Age:       "27",
    Alternate: []string{"Samantha Holder"},


Answered By – The Fool

Answer Checked By – David Goodson (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.