Last active
December 16, 2021 18:00
-
-
Save vaguecoder/8ed8424f3757abd3d88bf73bdf7db5df to your computer and use it in GitHub Desktop.
JSON Marshal-Unmarshal vs Encoding-Decoding in Go (golang)
This file contains 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
type Character struct { | |
Name string `json:"name"` | |
Designation []string `json:"designation"` | |
Age int `json:"age"` | |
Moves []Move `json:"moves"` | |
} | |
type Move struct { | |
Name string `json:"move"` | |
Power int `json:"power"` | |
} | |
var ( | |
data = []Character{ | |
{ | |
Name: "Monkey D Luffy", | |
Designation: []string{ | |
"King of the Pirates", | |
"Captain of Straw Hats", | |
"Rubber Man", | |
}, | |
Age: 17, | |
Moves: []Move{ | |
{"Gum Gum Bazooka", 2500}, | |
{"Gum Gum Gatling", 2000}, | |
}, | |
}, | |
{ | |
Name: "Rovanova Zoro", | |
Designation: []string{ | |
"World's Greatest Swordsman", | |
"First Mate of Straw Hats", | |
"Pirate Hunter", | |
}, | |
Age: 19, | |
Moves: []Move{ | |
{"108 Caliber Phoenix", 2000}, | |
{"Lion's Strike", 1500}, | |
}, | |
}, | |
{ | |
Name: "Nami", | |
Designation: []string{ | |
"Navigator", | |
"Pirate Thief", | |
}, | |
Age: 18, | |
Moves: []Move{ | |
{"Thunderbolt Tempo", 1000}, | |
{"Clima-Tact", 800}, | |
}, | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment