Trying to teach myself some Go by following an online course. And I'm trying to go a bit off course to expand on my learning a bit.
The course had us writing a simple function using a couple variables and the function would take the two variables and print out a line. So I had:
func main() {
var greeting := "hello"
var name := "cleveland"
message := printMessage(greeting,name)
fmt.Println(message)
}
func printMessage(greeting string, name string) (message string) {
return greeting + " " + name + "!"
}
Later the course introduced a way to create an pseudo-array of strings using the using the
func sayHello (cities ...string) (message string) {
for _, city := range cities {
message := printMessage("hello", city)
fmt.Println(message)
}
}
I would like to create a struct with different greetings and pass those into the sayHello function. So the struct and the variables would looks something like this:
type cityInfo struct {
greeting string
name string
wins float32
gamesPlayed float32
}
city1 := cityInfo{"hello", "cleveland"}
city2 := cityInfo{"good morning", "atlanta"}
...and so on
How do I format the function to pass those structs into the function so that I can iterate on the number of structs and get the greetings and names using city.greeting and city.name? Does this question make sense?