Unable to assign the value to struct slice datatype via (:=)

package main

import “fmt”

type Hospital struct {
name1 string
phone int
}
type Doctors struct {
Hospital
id int
name string
patients []string
}

func main() {
doc := Doctors{}
var
doc.name1 = “Govt”
doc.phone = 123456
doc.id = 11
doc.name = “tinq”
doc.patients :=[]string{“Jone”,“David”}

How to assingn a value for patients field?

Getting this error:
./prog.go:24:2: non-name doc.patients on left side of :=

You want to use = instead of := in the mentioned location.

Also please use proper code blocks, either using indention or fences.

Alternatively select the code and then click on the </> in the toolbar

1 Like

Thankyou

1 Like