Skip to content

Instantly share code, notes, and snippets.

@jjuliano
Last active December 16, 2019 11:07
Show Gist options
  • Save jjuliano/6d115b48be3c3b8313487d966006b530 to your computer and use it in GitHub Desktop.
Save jjuliano/6d115b48be3c3b8313487d966006b530 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type basket []map[string]string
func main() {
basket := new(basket)
basket.add_item(map[string]string{
"name": "apple",
"flavour": "It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general.",
}, "fruit")
basket.print_items()
}
func (items *basket) add_item(args ...interface{}) {
item := args[0].(map[string]string)
item["kind"] = args[1].(string)
*items = append(*items, item)
fmt.Printf("Entry %s created!\n", item["name"])
}
func (items basket) print_items() {
fmt.Println()
fmt.Printf("There are %d item(s) in the basket.\n", len(items))
for _, item := range items {
fmt.Println()
fmt.Printf("Name: %s\nFlavour: %s\nKind: %s\n", item["name"], item["flavour"], item["kind"])
}
}
// Entry apple created!
//
// There are 1 item(s) in the basket.
//
// Name: apple
// Flavour: It's a little sour and bitter, but mostly sweet, not at all salty, very juicy in general.
// Kind: fruit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment