I want to initialize a composite structure. The composite structure has json tags, and when running the program it shows something like the following:
go run struct.go
# command-line-arguments
./struct.go:23:11: cannot use struct { Lat float32; Lon float32 } literal (type struct { Lat float32; Lon float32 }) as type struct { Lat float32 "json:\"lat\""; Lon float32 "json:\"lon\"" } in field value
Someone who can tell me what I'm missing or what I'm doing wrong?
The program with which I am doing tests is the following:
package main
import "fmt"
type Document struct {
Ciudad string 'json:"ciudad"'
Colonia string 'json:"colonia"'
Cp int 'json:"cp"'
Delegacion string 'json:"delegacion"'
Location struct {
Lat float32 'json:"lat"'
Lon float32 'json:"lon"'
} 'json:"location"'
}
func main() {
d := &Document{
Ciudad: "xxxx xxxx",
Colonia: "yyyy yyyy",
Cp: 3333,
Delegacion: "zzzz zzzz",
Location: struct {
Lat float32
Lon float32
}{
Lat: -111.111,
Lon: 111.111,
},
}
fmt.Printf("%v", d)
}
Here I leave the league with the program in the playground version of go: