Skip to content

Instantly share code, notes, and snippets.

@jjuliano
Last active December 16, 2019 11:04
Show Gist options
  • Save jjuliano/b87408af41a3a161280e9ce234fbff0a to your computer and use it in GitHub Desktop.
Save jjuliano/b87408af41a3a161280e9ce234fbff0a to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
produce := []interface{}{
map[string]string{
"name": "apple",
"flavour": "It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general.",
"kind": "fruit",
},
map[string]string{
"name": "cucumber",
"flavour": "Slightly bitter with a mild melon aroma and planty flavor.",
"kind": "veggies",
},
"water",
}
basket(produce...)
}
func basket(args ...interface{}) {
for _, item := range args {
item_type := fmt.Sprintf("%T", item)
if item_type == "map[string]string" {
produce := item.(map[string]string)
fmt.Printf("Name: %s\nFlavour: %s\nKind: %s\n\n", produce["name"], produce["flavour"], produce["kind"])
} else {
fmt.Println("You have passed a non-fruit or non-veggies argument", item.(string))
}
}
}
// Name: apple
// Flavour: It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general.
// Kind: fruit
//
// Name: cucumber
// Flavour: Slightly bitter with a mild melon aroma and planty flavor.
// Kind: veggies
//
// You have passed a non-fruit or non-veggies argument water
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment