コード例 #1
0
func cerca() {
	var chiave string
	fmt.Println("Titolo oppure Autore")
	fmt.Scanf("\n%s", &chiave)
	fmt.Println()
	books := writefile.ElencoLibri2()

	var keys []int
	for k := range books {
		keys = append(keys, k)
	}
	sort.Ints(keys)

	var booksV []*types.Book
	for key := range keys {
		if books[key].Titolo == chiave || books[key].Autore == chiave {
			booksV = append(booksV, books[key])

		}
	}
	for i := 0; i < len(booksV); i++ {
		fmt.Println(booksV[i])
	}

}
コード例 #2
0
func elencoMap() {
	books := writefile.ElencoLibri2()

	var keys []int
	for k := range books {
		keys = append(keys, k)
	}
	sort.Ints(keys)

	for key := range keys {
		fmt.Println("ID:", key, "\nTitolo:", books[key].Titolo, "\nAutore:", books[key].Autore)
	}

}