Last active
December 16, 2019 11:04
-
-
Save jjuliano/b87408af41a3a161280e9ce234fbff0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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