| 
									
										
										
										
											2019-05-09 14:10:09 +03:00
										 |  |  | // Copyright © 2018 Inanc Gumus | 
					
						
							|  |  |  | // Learn Go Programming Course | 
					
						
							|  |  |  | // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | 
					
						
							|  |  |  | // | 
					
						
							| 
									
										
										
										
											2019-10-30 19:34:44 +03:00
										 |  |  | // For more tutorials  : https://learngoprogramming.com | 
					
						
							|  |  |  | // In-person training  : https://www.linkedin.com/in/inancgumus/ | 
					
						
							|  |  |  | // Follow me on twitter: https://twitter.com/inancgumus | 
					
						
							| 
									
										
										
										
											2019-05-09 14:10:09 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --------------------------------------------------------- | 
					
						
							|  |  |  | // EXERCISE: Decode | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  At the beginning of the file: | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  1. Load the initial data to the game store from json. | 
					
						
							|  |  |  | //     (see the data constant below) | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  2. Load the decoded values into the usual `game` values (to the games slice as well). | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //     So the rest of the program can work intact. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // HINT | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  Move the jsonGame type to the top and reuse it both when | 
					
						
							|  |  |  | //  loading the initial data, and in the "save" command. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // EXPECTED OUTPUT | 
					
						
							|  |  |  | //  Please run the solution to see the output. | 
					
						
							|  |  |  | // --------------------------------------------------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const data = ` | 
					
						
							|  |  |  | [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |                 "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 | 
					
						
							|  |  |  | } |