Skip to content

Commit

Permalink
good night
Browse files Browse the repository at this point in the history
  • Loading branch information
GoesToEleven committed Oct 31, 2015
1 parent d07c985 commit 307974c
Show file tree
Hide file tree
Showing 29 changed files with 186 additions and 206 deletions.
29 changes: 29 additions & 0 deletions 20_struct/04_method-sets/01_value-receiver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import "fmt"

type person struct {
first string
last string
age int
}

func (p *person) fullName() string {
fmt.Printf("Inside method: %p\n", &p)
return p.first + p.last
}

func main() {
p1 := person{"James", "Bond", 20}
p2 := &person{"Miss", "Moneypenny", 18}

// address in main is different from address in method
fmt.Println(p1.fullName())
fmt.Printf("Inside main: %p\n", &p1)

// method works for either a value or pointer
fmt.Println(p2.fullName())
}

// p1 is the receiver value for the call to fullName
// fullName is operating on its own value of p1
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions 20_struct/08_marshal_unmarshal/01_marshal/01_exported/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"encoding/json"
"fmt"
)

type Person struct {
First string
Last string
Age int
notExported int
}

func main() {
p1 := Person{"James", "Bond", 20, 007}
bs, _ := json.Marshal(p1)
fmt.Println(bs)
fmt.Printf("%T \n", bs)
fmt.Println(string(bs))
}
19 changes: 19 additions & 0 deletions 20_struct/08_marshal_unmarshal/01_marshal/02_unexported/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"encoding/json"
"fmt"
)

type Person struct {
first string
last string
age int
}

func main() {
p1 := Person{"James", "Bond", 20}
fmt.Println(p1)
bs, _ := json.Marshal(p1)
fmt.Println(string(bs))
}
18 changes: 18 additions & 0 deletions 20_struct/08_marshal_unmarshal/01_marshal/03_tags/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"encoding/json"
"fmt"
)

type Person struct {
First string
Last string `json:"-"`
Age int `json:"wisdom score"`
}

func main() {
p1 := Person{"James", "Bond", 20}
bs, _ := json.Marshal(p1)
fmt.Println(string(bs))
}
29 changes: 29 additions & 0 deletions 20_struct/08_marshal_unmarshal/02_unmarshal/01/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"encoding/json"
"fmt"
)

type Person struct {
First string
Last string
Age int
}

func main() {
var p1 Person
fmt.Println(p1.First)
fmt.Println(p1.Last)
fmt.Println(p1.Age)

bs := []byte(`{"First":"James", "Last":"Bond", "Age":20}`)
json.Unmarshal(bs, &p1)


fmt.Println("--------------")
fmt.Println(p1.First)
fmt.Println(p1.Last)
fmt.Println(p1.Age)
fmt.Printf("%T \n", p1)
}
28 changes: 28 additions & 0 deletions 20_struct/08_marshal_unmarshal/02_unmarshal/02_tags/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"encoding/json"
"fmt"
)

type Person struct {
First string
Last string
Age int `json:"wisdom score"`
}

func main() {
var p1 Person
fmt.Println(p1.First)
fmt.Println(p1.Last)
fmt.Println(p1.Age)

bs := []byte(`{"First":"James", "Last":"Bond", "wisdom score":20}`)
json.Unmarshal(bs, &p1)

fmt.Println("--------------")
fmt.Println(p1.First)
fmt.Println(p1.Last)
fmt.Println(p1.Age)
fmt.Printf("%T \n", p1)
}
18 changes: 18 additions & 0 deletions 20_struct/09_encode_decode/01_encode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"encoding/json"
"os"
)

type Person struct {
First string
Last string
Age int
notExported int
}

func main() {
p1 := Person{"James", "Bond", 20, 007}
json.NewEncoder(os.Stdout).Encode(p1)
}
24 changes: 24 additions & 0 deletions 20_struct/09_encode_decode/02_decode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"encoding/json"
"strings"
"fmt"
)

type Person struct {
First string
Last string
Age int
notExported int
}

func main() {
var p1 Person
str := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`)
json.NewDecoder(str).Decode(&p1)

fmt.Println(p1.First)
fmt.Println(p1.Last)
fmt.Println(p1.Age)
}
13 changes: 0 additions & 13 deletions 22_new_make_HMMMMMMMMM/01_make/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions 22_new_make_HMMMMMMMMM/02_new-int/main.go

This file was deleted.

10 changes: 0 additions & 10 deletions 22_new_make_HMMMMMMMMM/03_new-string/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions 22_new_make_HMMMMMMMMM/04_new-bool/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions 22_new_make_HMMMMMMMMM/05_new-slice/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions 22_new_make_HMMMMMMMMM/06_new-map/main.go

This file was deleted.

8 changes: 0 additions & 8 deletions 22_new_make_HMMMMMMMMM/07_make-error_invalid-code/main.go

This file was deleted.

12 changes: 0 additions & 12 deletions 22_new_make_HMMMMMMMMM/08_new_make_slice-int/main.go

This file was deleted.

12 changes: 0 additions & 12 deletions 22_new_make_HMMMMMMMMM/09_new_make_slice-string/main.go

This file was deleted.

16 changes: 0 additions & 16 deletions 22_new_make_HMMMMMMMMM/10_new_make_map-int-int/main.go

This file was deleted.

21 changes: 0 additions & 21 deletions 23_methods/01_struct/main.go

This file was deleted.

20 changes: 0 additions & 20 deletions 23_methods/02_struct_value-receiver/01/main.go

This file was deleted.

23 changes: 0 additions & 23 deletions 23_methods/02_struct_value-receiver/02/main.go

This file was deleted.

Loading

0 comments on commit 307974c

Please sign in to comment.