add: json encoding/decoding quiz and exercises
This commit is contained in:
65
24-structs/exercises/04-encode/main.go
Normal file
65
24-structs/exercises/04-encode/main.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Encode
|
||||
//
|
||||
// Add a new command: "save". Encode the games to json, and
|
||||
// print it, then terminate the loop.
|
||||
//
|
||||
// 1. Create a new struct type with exported fields: ID, Name, Genre and Price.
|
||||
//
|
||||
// 2. Create a new slice using the new struct type.
|
||||
//
|
||||
// 3. Save the games into the new slice.
|
||||
//
|
||||
// 4. Encode the new slice.
|
||||
//
|
||||
//
|
||||
// RESTRICTION
|
||||
// Do not export the fields of the game struct.
|
||||
//
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// Inanc's game store has 3 games.
|
||||
//
|
||||
// > list : lists all the games
|
||||
// > id N : queries a game by id
|
||||
// > save : exports the data to json and quits
|
||||
// > quit : quits
|
||||
//
|
||||
// save
|
||||
//
|
||||
// [
|
||||
// {
|
||||
// "id": 1,
|
||||
// "name": "god of war",
|
||||
// "genre": "action adventure",
|
||||
// "price": 50
|
||||
// },
|
||||
// {
|
||||
// "id": 2,
|
||||
// "name": "x-com 2",
|
||||
// "genre": "strategy",
|
||||
// "price": 40
|
||||
// },
|
||||
// {
|
||||
// "id": 3,
|
||||
// "name": "minecraft",
|
||||
// "genre": "sandbox",
|
||||
// "price": 20
|
||||
// }
|
||||
// ]
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// use your solution from the previous exercise
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user