From 54b57afa06e69b3eafbb7ede23d5735d0d76e78a Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Wed, 17 Apr 2019 23:28:50 +0300 Subject: [PATCH] move: structs to root --- .../2-structs => 24-structs}/01-intro/main.go | 0 .../02-basics/main.go | 0 .../03-compare-assign/main.go | 0 .../04-embedding/main.go | 0 {x-tba/2-structs => 24-structs}/TODO.md | 9 ++-- .../exercises/00-name/main.go | 0 .../exercises/00-name/solution/main.go | 0 .../exercises/README.md | 0 24-structs/xxx-wizards/marshal/main.go | 31 ++++++++++++ .../xxx-wizards}/unmarshal/main.go | 12 +++-- x-tba/2-structs/README.md | 1 - x-tba/2-structs/xxx-using-in-maps/main.go | 19 -------- .../2-structs/xxx-wizards/cmd/marshal/main.go | 47 ------------------- .../xxx-wizards/cmd/marshal/wizards.json | 1 - x-tba/2-structs/xxx-wizards/wizards.go | 9 ---- 15 files changed, 44 insertions(+), 85 deletions(-) rename {x-tba/2-structs => 24-structs}/01-intro/main.go (100%) rename {x-tba/2-structs => 24-structs}/02-basics/main.go (100%) rename {x-tba/2-structs => 24-structs}/03-compare-assign/main.go (100%) rename {x-tba/2-structs => 24-structs}/04-embedding/main.go (100%) rename {x-tba/2-structs => 24-structs}/TODO.md (68%) rename {x-tba/2-structs => 24-structs}/exercises/00-name/main.go (100%) rename {x-tba/2-structs => 24-structs}/exercises/00-name/solution/main.go (100%) rename {x-tba/2-structs => 24-structs}/exercises/README.md (100%) create mode 100644 24-structs/xxx-wizards/marshal/main.go rename {x-tba/2-structs/xxx-wizards/cmd => 24-structs/xxx-wizards}/unmarshal/main.go (62%) delete mode 100644 x-tba/2-structs/README.md delete mode 100644 x-tba/2-structs/xxx-using-in-maps/main.go delete mode 100644 x-tba/2-structs/xxx-wizards/cmd/marshal/main.go delete mode 100644 x-tba/2-structs/xxx-wizards/cmd/marshal/wizards.json delete mode 100644 x-tba/2-structs/xxx-wizards/wizards.go diff --git a/x-tba/2-structs/01-intro/main.go b/24-structs/01-intro/main.go similarity index 100% rename from x-tba/2-structs/01-intro/main.go rename to 24-structs/01-intro/main.go diff --git a/x-tba/2-structs/02-basics/main.go b/24-structs/02-basics/main.go similarity index 100% rename from x-tba/2-structs/02-basics/main.go rename to 24-structs/02-basics/main.go diff --git a/x-tba/2-structs/03-compare-assign/main.go b/24-structs/03-compare-assign/main.go similarity index 100% rename from x-tba/2-structs/03-compare-assign/main.go rename to 24-structs/03-compare-assign/main.go diff --git a/x-tba/2-structs/04-embedding/main.go b/24-structs/04-embedding/main.go similarity index 100% rename from x-tba/2-structs/04-embedding/main.go rename to 24-structs/04-embedding/main.go diff --git a/x-tba/2-structs/TODO.md b/24-structs/TODO.md similarity index 68% rename from x-tba/2-structs/TODO.md rename to 24-structs/TODO.md index 2d48e15..5097420 100644 --- a/x-tba/2-structs/TODO.md +++ b/24-structs/TODO.md @@ -7,14 +7,13 @@ [x] struct fields [x] compare and assign [x] printing -[ ] embedding +[x] embedding +[ ] exporting struct and fields +[ ] struct tags {json encode/decode} - project? **LATER:** -[ ] exporting struct and fields [ ] funcs: constructor pattern -[ ] using anonymous structs when testing [ ] pointers: - [ ] struct tags {json encode/decode} - project? [ ] structs and pointers - later [ ] padding and memory layout - later -[ ] empty struct (in channels section) \ No newline at end of file +[ ] using anonymous structs when testing \ No newline at end of file diff --git a/x-tba/2-structs/exercises/00-name/main.go b/24-structs/exercises/00-name/main.go similarity index 100% rename from x-tba/2-structs/exercises/00-name/main.go rename to 24-structs/exercises/00-name/main.go diff --git a/x-tba/2-structs/exercises/00-name/solution/main.go b/24-structs/exercises/00-name/solution/main.go similarity index 100% rename from x-tba/2-structs/exercises/00-name/solution/main.go rename to 24-structs/exercises/00-name/solution/main.go diff --git a/x-tba/2-structs/exercises/README.md b/24-structs/exercises/README.md similarity index 100% rename from x-tba/2-structs/exercises/README.md rename to 24-structs/exercises/README.md diff --git a/24-structs/xxx-wizards/marshal/main.go b/24-structs/xxx-wizards/marshal/main.go new file mode 100644 index 0000000..a55f293 --- /dev/null +++ b/24-structs/xxx-wizards/marshal/main.go @@ -0,0 +1,31 @@ +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)) +} diff --git a/x-tba/2-structs/xxx-wizards/cmd/unmarshal/main.go b/24-structs/xxx-wizards/unmarshal/main.go similarity index 62% rename from x-tba/2-structs/xxx-wizards/cmd/unmarshal/main.go rename to 24-structs/xxx-wizards/unmarshal/main.go index 7c33ba8..d22786e 100644 --- a/x-tba/2-structs/xxx-wizards/cmd/unmarshal/main.go +++ b/24-structs/xxx-wizards/unmarshal/main.go @@ -5,17 +5,23 @@ import ( "fmt" "io/ioutil" "strings" - - "github.com/inancgumus/learngo/x-tba/structs/xxx-json/wizards" ) +// 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([]wizards.Wizard, 10) + wizards := make([]Wizard, 10) if json.Unmarshal(file, &wizards) != nil { panic(err) } diff --git a/x-tba/2-structs/README.md b/x-tba/2-structs/README.md deleted file mode 100644 index 58094c8..0000000 --- a/x-tba/2-structs/README.md +++ /dev/null @@ -1 +0,0 @@ -This section is in progress. I'm working hard to update the course all the time. Hold on! \ No newline at end of file diff --git a/x-tba/2-structs/xxx-using-in-maps/main.go b/x-tba/2-structs/xxx-using-in-maps/main.go deleted file mode 100644 index f39d174..0000000 --- a/x-tba/2-structs/xxx-using-in-maps/main.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import "fmt" - -func main() { - type book struct { - name, isbn string - } - - kafka := book{"Kafka's Revenge", "S-001"} - golden := book{"Stay Golden", "S-002"} - - books := make(map[book]int, 2) - books[kafka] = 100 - books[golden] = 50 - - fmt.Printf("%s sold %d times\n", kafka.name, books[kafka]) - fmt.Printf("%s sold %d times\n", golden.name, books[golden]) -} diff --git a/x-tba/2-structs/xxx-wizards/cmd/marshal/main.go b/x-tba/2-structs/xxx-wizards/cmd/marshal/main.go deleted file mode 100644 index 4fe6503..0000000 --- a/x-tba/2-structs/xxx-wizards/cmd/marshal/main.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "encoding/json" - "io/ioutil" - - "github.com/inancgumus/learngo/x-tba/structs/xxx-json/wizards" -) - -func main() { - wizards := []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) - } - - ioutil.WriteFile("wizards.json", bytes, 0644) - - // - // PREVIOUSLY - // - - // names := [...][3]string{ - // {"First Name", "Last Name", "Nickname"}, - // {"Albert", "Einstein", "emc2"}, - // {"Isaac", "Newton", "apple"}, - // {"Stephen", "Hawking", "blackhole"}, - // {"Marie", "Curie", "radium"}, - // {"Charles", "Darwin", "fittest"}, - // } - - // for i := range names { - // n := names[i] - // fmt.Printf("%-15s %-15s %-15s\n", n[0], n[1], n[2]) - - // if i == 0 { - // fmt.Println(strings.Repeat("=", 50)) - // } - // } -} diff --git a/x-tba/2-structs/xxx-wizards/cmd/marshal/wizards.json b/x-tba/2-structs/xxx-wizards/cmd/marshal/wizards.json deleted file mode 100644 index e73e71e..0000000 --- a/x-tba/2-structs/xxx-wizards/cmd/marshal/wizards.json +++ /dev/null @@ -1 +0,0 @@ -[{"Name":"Albert","nick":"emc2"},{"Name":"Isaac","nick":"apple"},{"Name":"Stephen","nick":"blackhole"},{"Name":"Marie","nick":"radium"},{"Name":"Charles","nick":"fittest"}] \ No newline at end of file diff --git a/x-tba/2-structs/xxx-wizards/wizards.go b/x-tba/2-structs/xxx-wizards/wizards.go deleted file mode 100644 index 121cc85..0000000 --- a/x-tba/2-structs/xxx-wizards/wizards.go +++ /dev/null @@ -1,9 +0,0 @@ -package wizards - -// 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"` -}