You don't need to declare the variable type beforehand, at least not in this simple example, although you need to "mention" your types when initializing your values with composite literals.
For example this [{}]
(array of objects?) makes no sense to the Go compiler, instead you need to write something like this []map[string]interface{}{}
(slice of maps whose keys are strings and whose values can have any type)
To break it down:
[]
- slice of whatever type comes after it
map
- builtin map (think hash)
[string]
- inside the square brackets is the type of the map key,
can be almost any type
interface{}
- the type of the map values
{}
- this initializes/allocate the whole thing
So your example in Go would look something like this:
var Array = []map[string]interface{}{
{"name":"Tom", "dates": []int{20170522, 20170622}, "images": map[string]string{"profile": "assets/tom-profile", "full": "assets/tom-full"}},
{"name":"Pat", "dates": []int{20170515, 20170520}, "images": map[string]string{"profile": "assets/pat-profile", "full": "assets/pat-full"}},
// ...
}
Read more on maps and what key types you can use here: https://golang.org/ref/spec#Map_types
That said, in Go, most of the time, you would first define your structured types more concretely and then use them instead of maps, so something like this makes more sense in Go:
type User struct {
Name string
Dates []int
Images Images
}
type Images struct {
Profile string
Full string
}
var Array = []User{
{Name:"Tom", Dates:[]int{20170522, 20170622}, Images:Images{Profile:"assets/tom-profile", Full:"assets/tom-full"}},
{Name:"Pat", Dates:[]int{20170515, 20170520}, Images:Images{Profile:"assets/pat-profile", Full:"assets/pat-full"}},
}