What is called a 'hash' in Ruby is called a 'map' (translating keys to values) in Go.
However, Go is a statically typechecked language. A map can only map a certain type to another type, e.g. a map[string]int maps string values to integeger. That is not what you want here.
So what you want is a struct. Indeed, you need to define the type beforehand. So what you would do:
// declaring a separate 'Date' type that you may or may not want to encode as int.
type Date int
type User struct {
Name string
Dates []Date
Images map[string]string
}
Now that this type is defined, you can use it in another type:
ar := []User{
User{
Name: "Tom",
Dates: []Date{20170522, 20170622},
Images: map[string]string{"profile":"assets/tom-profile", "full": "assets/tom-full"},
},
User{
Name: "Pat",
Dates: []Date{20170515, 20170520},
Images: map[string]string{"profile":"assets/pat-profile", "full": "assets/pat-full"},
},
}
Note how we are defining User as a struct, but images as a map of string to image. You could also define a separate Image type:
type Image struct {
Type string // e.g. "profile"
Path string // e.g. "assets/tom-profile"
}
You would then not define Images as map[string]string
but as []Image
, that is, slice of Image structs. Which one is more appropriate depends on the use case.