move: wizards structs project to x-tba

This commit is contained in:
Inanc Gumus
2019-04-23 00:30:12 +03:00
parent 6f02276343
commit 15aeccdd4b
6 changed files with 107 additions and 6 deletions

View File

@ -1,31 +0,0 @@
package main
import (
"encoding/json"
"fmt"
)
// Wizard is one of the greatest of people
type Wizard struct {
// name won't be marshalled (should be exported)
Name string `json:name`
Lastname string `json:"-"`
Nick string `json:"nick"`
}
func main() {
wizards := []Wizard{
{Name: "Albert", Lastname: "Einstein", Nick: "emc2"},
{Name: "Isaac", Lastname: "Newton", Nick: "apple"},
{Name: "Stephen", Lastname: "Hawking", Nick: "blackhole"},
{Name: "Marie", Lastname: "Curie", Nick: "radium"},
{Name: "Charles", Lastname: "Darwin", Nick: "fittest"},
}
bytes, err := json.Marshal(wizards)
if err != nil {
panic(err)
}
fmt.Print(string(bytes))
}

View File

@ -1,35 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
// Wizard is one of the greatest of people
type Wizard struct {
// name won't be marshalled (should be exported)
Name string `json:name`
Lastname string `json:"-"`
Nick string `json:"nick"`
}
func main() {
file, err := ioutil.ReadFile("../marshal/wizards.json")
if err != nil {
panic(err)
}
wizards := make([]Wizard, 10)
if json.Unmarshal(file, &wizards) != nil {
panic(err)
}
fmt.Printf("%-15s %-15s\n%s",
"Name", "Nick", strings.Repeat("=", 25))
for _, w := range wizards {
fmt.Printf("%-15s %-15s\n", w.Name, w.Nick)
}
}