From 153afe0b1087a9c6882100a408e59de71b00d51f Mon Sep 17 00:00:00 2001 From: LucaPaterlini Date: Sun, 28 Jul 2019 16:27:40 +0100 Subject: [PATCH 1/3] chapter 1 added anonymous function (wrong implmentation page 21) --- .gitignore | 3 +++ Chapter01/anonymous_functions/main.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 Chapter01/anonymous_functions/main.go diff --git a/.gitignore b/.gitignore index cd2946a..4955ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk + +# Intellij ide +./idea diff --git a/Chapter01/anonymous_functions/main.go b/Chapter01/anonymous_functions/main.go new file mode 100644 index 0000000..9f30930 --- /dev/null +++ b/Chapter01/anonymous_functions/main.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func main(){ + add := func (m int)int{ + return m+1 + } + result := add(6) + // 1+6 must print 7 + fmt.Println(result) +} + From 06910bc6ed4bbfbb55f27ae8e36816846d3147c8 Mon Sep 17 00:00:00 2001 From: LucaPaterlini Date: Sun, 28 Jul 2019 16:28:34 +0100 Subject: [PATCH 2/3] chapter 1 added closures (wrong implmentation page 22) --- Chapter01/closures/closures.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Chapter01/closures/closures.go diff --git a/Chapter01/closures/closures.go b/Chapter01/closures/closures.go new file mode 100644 index 0000000..b2029e5 --- /dev/null +++ b/Chapter01/closures/closures.go @@ -0,0 +1,15 @@ +package main + +import "fmt" + + +func main(){ + addN := func(m int)func(int)int{ + return func(n int)int{ + return m+n + } + } + addFive := addN(5) + result := addFive(6) + fmt.Println(result) +} \ No newline at end of file From ea2c78942030065b75c0a3c62bfb6efd59b32491 Mon Sep 17 00:00:00 2001 From: LucaPaterlini Date: Sun, 28 Jul 2019 16:29:31 +0100 Subject: [PATCH 3/3] chapter 1 added the encoding package snippet (wrong implmentation page 43 return carriage before json) --- .idea/.gitignore | 3 +++ Chapter01/the_encoding_package/encoding.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 Chapter01/the_encoding_package/encoding.go diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/Chapter01/the_encoding_package/encoding.go b/Chapter01/the_encoding_package/encoding.go new file mode 100644 index 0000000..750cc66 --- /dev/null +++ b/Chapter01/the_encoding_package/encoding.go @@ -0,0 +1,14 @@ +package main + +import "encoding/json" +import "fmt" + +type MyObject struct { + Number int `json:"number"` + Word string +} +func main(){ + object := MyObject{5, "Packt"} + oJson, _ := json.Marshal(object) + fmt.Printf("%s\n", oJson) +} \ No newline at end of file