diff --git a/08_pointers/01_referencing/main.go b/08_pointers/01_referencing/main.go index c84d0c1a..c0bfd658 100644 --- a/08_pointers/01_referencing/main.go +++ b/08_pointers/01_referencing/main.go @@ -11,7 +11,7 @@ func main() { fmt.Println(a) fmt.Println(&a) - var b *int = &a + var b = &a fmt.Println(b) diff --git a/08_pointers/02_dereferencing/main.go b/08_pointers/02_dereferencing/main.go index e9f7e906..9ba6c384 100644 --- a/08_pointers/02_dereferencing/main.go +++ b/08_pointers/02_dereferencing/main.go @@ -9,7 +9,7 @@ func main() { fmt.Println(a) // 43 fmt.Println(&a) // 0x20818a220 - var b *int = &a + var b = &a fmt.Println(b) // 0x20818a220 fmt.Println(*b) // 43 diff --git a/08_pointers/03_using-pointers/main.go b/08_pointers/03_using-pointers/main.go index e06276c1..e9572c31 100644 --- a/08_pointers/03_using-pointers/main.go +++ b/08_pointers/03_using-pointers/main.go @@ -9,7 +9,7 @@ func main() { fmt.Println(a) // 43 fmt.Println(&a) // 0x20818a220 - var b *int = &a + var b = &a fmt.Println(b) // 0x20818a220 fmt.Println(*b) // 43 diff --git a/11_switch-statements/05_on-type/type.go b/11_switch-statements/05_on-type/type.go index 0c0622a3..1e948182 100644 --- a/11_switch-statements/05_on-type/type.go +++ b/11_switch-statements/05_on-type/type.go @@ -6,11 +6,12 @@ import "fmt" // -- normally we switch on value of variable // -- go allows you to switch on type of variable -type Contact struct { +type contact struct { greeting string name string } +// SwitchOnType works with interfaces // we'll learn more about interfaces later func SwitchOnType(x interface{}) { switch x.(type) { // this is an assert; asserting, "x is of this type" @@ -18,7 +19,7 @@ func SwitchOnType(x interface{}) { fmt.Println("int") case string: fmt.Println("string") - case Contact: + case contact: fmt.Println("contact") default: fmt.Println("unknown") @@ -29,7 +30,7 @@ func SwitchOnType(x interface{}) { func main() { SwitchOnType(7) SwitchOnType("McLeod") - var t = Contact{"Good to see you,", "Tim"} + var t = contact{"Good to see you,", "Tim"} SwitchOnType(t) SwitchOnType(t.greeting) SwitchOnType(t.name) diff --git a/14_functions/15_passing-by-value/07_struct-pointer/main.go b/14_functions/15_passing-by-value/07_struct-pointer/main.go index 884e2ab5..381077cb 100644 --- a/14_functions/15_passing-by-value/07_struct-pointer/main.go +++ b/14_functions/15_passing-by-value/07_struct-pointer/main.go @@ -2,13 +2,13 @@ package main import "fmt" -type Customer struct { +type customer struct { name string age int } func main() { - c1 := Customer{"Todd", 44} + c1 := customer{"Todd", 44} fmt.Println(&c1.name) // 0x8201e4120 changeMe(&c1) @@ -17,7 +17,7 @@ func main() { fmt.Println(&c1.name) // 0x8201e4120 } -func changeMe(z *Customer) { +func changeMe(z *customer) { fmt.Println(z) // &{Todd 44} fmt.Println(&z.name) // 0x8201e4120 z.name = "Rocky" diff --git a/18_slice/05_slicing-a-slice/01/main.go b/18_slice/05_slicing-a-slice/01/main.go index f9ecbbe0..23c9582c 100644 --- a/18_slice/05_slicing-a-slice/01/main.go +++ b/18_slice/05_slicing-a-slice/01/main.go @@ -1 +1,15 @@ -package _1 +package main + +import "fmt" + +func main() { + + var results []int + fmt.Println(results) + + mySlice := []string{"a", "b", "c", "g", "m", "z"} + fmt.Println(mySlice) + fmt.Println(mySlice[2:4]) // slicing a slice + fmt.Println(mySlice[2]) // index access; accessing by index + fmt.Println("myString"[2]) // index access; accessing by index +} diff --git a/18_slice/05_slicing-a-slice/02/main.go b/18_slice/05_slicing-a-slice/02/main.go index 23c9582c..eec50ea8 100644 --- a/18_slice/05_slicing-a-slice/02/main.go +++ b/18_slice/05_slicing-a-slice/02/main.go @@ -4,12 +4,22 @@ import "fmt" func main() { - var results []int - fmt.Println(results) - - mySlice := []string{"a", "b", "c", "g", "m", "z"} - fmt.Println(mySlice) - fmt.Println(mySlice[2:4]) // slicing a slice - fmt.Println(mySlice[2]) // index access; accessing by index - fmt.Println("myString"[2]) // index access; accessing by index + greeting := []string{ + "Good morning!", + "Bonjour!", + "dias!", + "Bongiorno!", + "Ohayo!", + "Selamat pagi!", + "Gutten morgen!", + } + + fmt.Print("[1:2] ") + fmt.Println(greeting[1:2]) + fmt.Print("[:2] ") + fmt.Println(greeting[:2]) + fmt.Print("[5:] ") + fmt.Println(greeting[5:]) + fmt.Print("[:] ") + fmt.Println(greeting[:]) } diff --git a/18_slice/05_slicing-a-slice/03/main.go b/18_slice/05_slicing-a-slice/03/main.go deleted file mode 100644 index eec50ea8..00000000 --- a/18_slice/05_slicing-a-slice/03/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import "fmt" - -func main() { - - greeting := []string{ - "Good morning!", - "Bonjour!", - "dias!", - "Bongiorno!", - "Ohayo!", - "Selamat pagi!", - "Gutten morgen!", - } - - fmt.Print("[1:2] ") - fmt.Println(greeting[1:2]) - fmt.Print("[:2] ") - fmt.Println(greeting[:2]) - fmt.Print("[5:] ") - fmt.Println(greeting[5:]) - fmt.Print("[:] ") - fmt.Println(greeting[:]) -} diff --git a/18_slice/12_multi-dimensional/05_slice-of-slice-of-string/main.go b/18_slice/12_multi-dimensional/05_slice-of-slice-of-string/main.go index ae9331e2..23353572 100644 --- a/18_slice/12_multi-dimensional/05_slice-of-slice-of-string/main.go +++ b/18_slice/12_multi-dimensional/05_slice-of-slice-of-string/main.go @@ -5,7 +5,7 @@ import ( ) func main() { - records := make([][]string, 0) + var records [][]string // student 1 student1 := make([]string, 4) student1[0] = "Foster" diff --git a/18_slice/12_multi-dimensional/06_slice-of-slice-of-int/main.go b/18_slice/12_multi-dimensional/06_slice-of-slice-of-int/main.go index c007c7b6..3980f9bf 100644 --- a/18_slice/12_multi-dimensional/06_slice-of-slice-of-int/main.go +++ b/18_slice/12_multi-dimensional/06_slice-of-slice-of-int/main.go @@ -9,7 +9,7 @@ func main() { transactions := make([][]int, 0, 3) for i := 0; i < 3; i++ { - transaction := make([]int, 0) + transaction := make([]int, 0, 4) for j := 0; j < 4; j++ { transaction = append(transaction, j) } diff --git a/19_map/14_hash-table/01_letter-buckets/05_hash-function/main.go b/19_map/14_hash-table/01_letter-buckets/05_hash-function/main.go index 43ec3afa..9f80826a 100644 --- a/19_map/14_hash-table/01_letter-buckets/05_hash-function/main.go +++ b/19_map/14_hash-table/01_letter-buckets/05_hash-function/main.go @@ -3,11 +3,11 @@ package main import "fmt" func main() { - n := HashBucket("Go", 12) + n := hashBucket("Go", 12) fmt.Println(n) } -func HashBucket(word string, buckets int) int { +func hashBucket(word string, buckets int) int { letter := int(word[0]) bucket := letter % buckets return bucket diff --git a/19_map/14_hash-table/01_letter-buckets/10_hash-letter-buckets/main.go b/19_map/14_hash-table/01_letter-buckets/10_hash-letter-buckets/main.go index 8bb3a1b0..528b81c1 100644 --- a/19_map/14_hash-table/01_letter-buckets/10_hash-letter-buckets/main.go +++ b/19_map/14_hash-table/01_letter-buckets/10_hash-letter-buckets/main.go @@ -23,7 +23,7 @@ func main() { buckets := make([]int, 200) // Loop over the words for scanner.Scan() { - n := HashBucket(scanner.Text()) + n := hashBucket(scanner.Text()) buckets[n]++ } fmt.Println(buckets[65:123]) @@ -33,6 +33,6 @@ func main() { // } } -func HashBucket(word string) int { +func hashBucket(word string) int { return int(word[0]) } diff --git a/19_map/14_hash-table/01_letter-buckets/11_hash-remainder-buckets/main.go b/19_map/14_hash-table/01_letter-buckets/11_hash-remainder-buckets/main.go index 6f09af47..70450394 100644 --- a/19_map/14_hash-table/01_letter-buckets/11_hash-remainder-buckets/main.go +++ b/19_map/14_hash-table/01_letter-buckets/11_hash-remainder-buckets/main.go @@ -23,13 +23,13 @@ func main() { buckets := make([]int, 12) // Loop over the words for scanner.Scan() { - n := HashBucket(scanner.Text(), 12) + n := hashBucket(scanner.Text(), 12) buckets[n]++ } fmt.Println(buckets) } -func HashBucket(word string, buckets int) int { +func hashBucket(word string, buckets int) int { letter := int(word[0]) bucket := letter % buckets return bucket diff --git a/19_map/14_hash-table/02_even-dstribution-hash/main.go b/19_map/14_hash-table/02_even-dstribution-hash/main.go index af489ce0..83b47cb1 100644 --- a/19_map/14_hash-table/02_even-dstribution-hash/main.go +++ b/19_map/14_hash-table/02_even-dstribution-hash/main.go @@ -23,13 +23,13 @@ func main() { buckets := make([]int, 12) // Loop over the words for scanner.Scan() { - n := HashBucket(scanner.Text(), 12) + n := hashBucket(scanner.Text(), 12) buckets[n]++ } fmt.Println(buckets) } -func HashBucket(word string, buckets int) int { +func hashBucket(word string, buckets int) int { var sum int for _, v := range word { sum += int(v) diff --git a/19_map/14_hash-table/03_words-in-buckets/01_slice-bucket/main.go b/19_map/14_hash-table/03_words-in-buckets/01_slice-bucket/main.go index 16752f36..6e33ae37 100644 --- a/19_map/14_hash-table/03_words-in-buckets/01_slice-bucket/main.go +++ b/19_map/14_hash-table/03_words-in-buckets/01_slice-bucket/main.go @@ -28,7 +28,7 @@ func main() { // Loop over the words for scanner.Scan() { word := scanner.Text() - n := HashBucket(word, 12) + n := hashBucket(word, 12) buckets[n] = append(buckets[n], word) } // Print len of each bucket @@ -39,7 +39,7 @@ func main() { // fmt.Println(buckets[6]) } -func HashBucket(word string, buckets int) int { +func hashBucket(word string, buckets int) int { var sum int for _, v := range word { sum += int(v) diff --git a/19_map/14_hash-table/03_words-in-buckets/02_map-bucket/main.go b/19_map/14_hash-table/03_words-in-buckets/02_map-bucket/main.go index f960202e..e7b10eb4 100644 --- a/19_map/14_hash-table/03_words-in-buckets/02_map-bucket/main.go +++ b/19_map/14_hash-table/03_words-in-buckets/02_map-bucket/main.go @@ -31,7 +31,7 @@ func main() { // Loop over the words for scanner.Scan() { word := scanner.Text() - n := HashBucket(word, 12) + n := hashBucket(word, 12) buckets[n][word]++ } // Print words in a bucket @@ -40,7 +40,7 @@ func main() { } } -func HashBucket(word string, buckets int) int { +func hashBucket(word string, buckets int) int { var sum int for _, v := range word { sum += int(v) diff --git a/19_map/14_hash-table/04_english-alphabet/02/main.go b/19_map/14_hash-table/04_english-alphabet/02/main.go index f64c680c..979941f0 100644 --- a/19_map/14_hash-table/04_english-alphabet/02/main.go +++ b/19_map/14_hash-table/04_english-alphabet/02/main.go @@ -27,7 +27,7 @@ func main() { } i := 0 - for k, _ := range words { + for k := range words { fmt.Println(k) if i == 200 { break diff --git a/20_struct/04_embedded-types/main.go b/20_struct/04_embedded-types/main.go index 843adc1f..9165e1ae 100644 --- a/20_struct/04_embedded-types/main.go +++ b/20_struct/04_embedded-types/main.go @@ -4,20 +4,20 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string Age int } -type DoubleZero struct { - Person +type doubleZero struct { + person LicenseToKill bool } func main() { - p1 := DoubleZero{ - Person: Person{ + p1 := doubleZero{ + person: person{ First: "James", Last: "Bond", Age: 20, @@ -25,8 +25,8 @@ func main() { LicenseToKill: true, } - p2 := DoubleZero{ - Person: Person{ + p2 := doubleZero{ + person: person{ First: "Miss", Last: "MoneyPenny", Age: 19, diff --git a/20_struct/05_promotion/01_overriding-fields/main.go b/20_struct/05_promotion/01_overriding-fields/main.go index 83aab0d8..4c5ca3c0 100644 --- a/20_struct/05_promotion/01_overriding-fields/main.go +++ b/20_struct/05_promotion/01_overriding-fields/main.go @@ -4,21 +4,21 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string Age int } -type DoubleZero struct { - Person +type doubleZero struct { + person First string LicenseToKill bool } func main() { - p1 := DoubleZero{ - Person: Person{ + p1 := doubleZero{ + person: person{ First: "James", Last: "Bond", Age: 20, @@ -27,8 +27,8 @@ func main() { LicenseToKill: true, } - p2 := DoubleZero{ - Person: Person{ + p2 := doubleZero{ + person: person{ First: "Miss", Last: "MoneyPenny", Age: 19, @@ -38,6 +38,6 @@ func main() { } // fields and methods of the inner-type are promoted to the outer-type - fmt.Println(p1.First, p1.Person.First) - fmt.Println(p2.First, p2.Person.First) + fmt.Println(p1.First, p1.person.First) + fmt.Println(p2.First, p2.person.First) } diff --git a/20_struct/05_promotion/01_overriding-fields/xxmain.go b/20_struct/05_promotion/01_overriding-fields/xxmain.go deleted file mode 100644 index 83aab0d8..00000000 --- a/20_struct/05_promotion/01_overriding-fields/xxmain.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "fmt" -) - -type Person struct { - First string - Last string - Age int -} - -type DoubleZero struct { - Person - First string - LicenseToKill bool -} - -func main() { - p1 := DoubleZero{ - Person: Person{ - First: "James", - Last: "Bond", - Age: 20, - }, - First: "Double Zero Seven", - LicenseToKill: true, - } - - p2 := DoubleZero{ - Person: Person{ - First: "Miss", - Last: "MoneyPenny", - Age: 19, - }, - First: "If looks could kill", - LicenseToKill: false, - } - - // fields and methods of the inner-type are promoted to the outer-type - fmt.Println(p1.First, p1.Person.First) - fmt.Println(p2.First, p2.Person.First) -} diff --git a/20_struct/05_promotion/02_overriding-methods/main.go b/20_struct/05_promotion/02_overriding-methods/main.go index e56beccd..3c1815d2 100644 --- a/20_struct/05_promotion/02_overriding-methods/main.go +++ b/20_struct/05_promotion/02_overriding-methods/main.go @@ -4,32 +4,32 @@ import ( "fmt" ) -type Person struct { +type person struct { Name string Age int } -type DoubleZero struct { - Person +type doubleZero struct { + person LicenseToKill bool } -func (p Person) Greeting() { +func (p person) Greeting() { fmt.Println("I'm just a regular person.") } -func (dz DoubleZero) Greeting() { +func (dz doubleZero) Greeting() { fmt.Println("Miss Moneypenny, so good to see you.") } func main() { - p1 := Person{ + p1 := person{ Name: "Ian Flemming", Age: 44, } - p2 := DoubleZero{ - Person: Person{ + p2 := doubleZero{ + person: person{ Name: "James Bond", Age: 23, }, @@ -37,5 +37,5 @@ func main() { } p1.Greeting() p2.Greeting() - p2.Person.Greeting() + p2.person.Greeting() } diff --git a/20_struct/07_marshal_unmarshal/01_marshal/01_exported/main.go b/20_struct/07_marshal_unmarshal/01_marshal/01_exported/main.go index 9d6b6ecb..65caab3a 100644 --- a/20_struct/07_marshal_unmarshal/01_marshal/01_exported/main.go +++ b/20_struct/07_marshal_unmarshal/01_marshal/01_exported/main.go @@ -5,7 +5,7 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string Age int @@ -13,7 +13,7 @@ type Person struct { } func main() { - p1 := Person{"James", "Bond", 20, 007} + p1 := person{"James", "Bond", 20, 007} bs, _ := json.Marshal(p1) fmt.Println(bs) fmt.Printf("%T \n", bs) diff --git a/20_struct/07_marshal_unmarshal/01_marshal/02_unexported/main.go b/20_struct/07_marshal_unmarshal/01_marshal/02_unexported/main.go index 8091e825..e92d8e8a 100644 --- a/20_struct/07_marshal_unmarshal/01_marshal/02_unexported/main.go +++ b/20_struct/07_marshal_unmarshal/01_marshal/02_unexported/main.go @@ -5,14 +5,14 @@ import ( "fmt" ) -type Person struct { +type person struct { first string last string age int } func main() { - p1 := Person{"James", "Bond", 20} + p1 := person{"James", "Bond", 20} fmt.Println(p1) bs, _ := json.Marshal(p1) fmt.Println(string(bs)) diff --git a/20_struct/07_marshal_unmarshal/01_marshal/03_tags/main.go b/20_struct/07_marshal_unmarshal/01_marshal/03_tags/main.go index 8a6b7fa0..aa8a7585 100644 --- a/20_struct/07_marshal_unmarshal/01_marshal/03_tags/main.go +++ b/20_struct/07_marshal_unmarshal/01_marshal/03_tags/main.go @@ -5,14 +5,14 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string `json:"-"` Age int `json:"wisdom score"` } func main() { - p1 := Person{"James", "Bond", 20} + p1 := person{"James", "Bond", 20} bs, _ := json.Marshal(p1) fmt.Println(string(bs)) } diff --git a/20_struct/07_marshal_unmarshal/02_unmarshal/01/main.go b/20_struct/07_marshal_unmarshal/02_unmarshal/01/main.go index 9fb6baf1..96d4dd8a 100644 --- a/20_struct/07_marshal_unmarshal/02_unmarshal/01/main.go +++ b/20_struct/07_marshal_unmarshal/02_unmarshal/01/main.go @@ -5,14 +5,14 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string Age int } func main() { - var p1 Person + var p1 person fmt.Println(p1.First) fmt.Println(p1.Last) fmt.Println(p1.Age) diff --git a/20_struct/07_marshal_unmarshal/02_unmarshal/02_tags/main.go b/20_struct/07_marshal_unmarshal/02_unmarshal/02_tags/main.go index 8cb6a038..292cb6a8 100644 --- a/20_struct/07_marshal_unmarshal/02_unmarshal/02_tags/main.go +++ b/20_struct/07_marshal_unmarshal/02_unmarshal/02_tags/main.go @@ -5,14 +5,14 @@ import ( "fmt" ) -type Person struct { +type person struct { First string Last string Age int `json:"wisdom score"` } func main() { - var p1 Person + var p1 person fmt.Println(p1.First) fmt.Println(p1.Last) fmt.Println(p1.Age) diff --git a/20_struct/08_encode_decode/01_encode/main.go b/20_struct/08_encode_decode/01_encode/main.go index e80b4ab1..181e1a55 100644 --- a/20_struct/08_encode_decode/01_encode/main.go +++ b/20_struct/08_encode_decode/01_encode/main.go @@ -5,7 +5,7 @@ import ( "os" ) -type Person struct { +type person struct { First string Last string Age int @@ -13,6 +13,6 @@ type Person struct { } func main() { - p1 := Person{"James", "Bond", 20, 007} + p1 := person{"James", "Bond", 20, 007} json.NewEncoder(os.Stdout).Encode(p1) } diff --git a/20_struct/08_encode_decode/02_decode/main.go b/20_struct/08_encode_decode/02_decode/main.go index 5f07f983..aa61204e 100644 --- a/20_struct/08_encode_decode/02_decode/main.go +++ b/20_struct/08_encode_decode/02_decode/main.go @@ -6,7 +6,7 @@ import ( "strings" ) -type Person struct { +type person struct { First string Last string Age int @@ -14,7 +14,7 @@ type Person struct { } func main() { - var p1 Person + var p1 person rdr := strings.NewReader(`{"First":"James", "Last":"Bond", "Age":20}`) json.NewDecoder(rdr).Decode(&p1) diff --git a/21_interfaces/05_conversion-vs-assertion/01_conversion/03_rune-to-string/main.go b/21_interfaces/05_conversion-vs-assertion/01_conversion/03_rune-to-string/main.go index 3636e6ef..cc74ebdb 100644 --- a/21_interfaces/05_conversion-vs-assertion/01_conversion/03_rune-to-string/main.go +++ b/21_interfaces/05_conversion-vs-assertion/01_conversion/03_rune-to-string/main.go @@ -3,7 +3,7 @@ package main import "fmt" func main() { - var x rune = 'a' // rune is an alias for int32 + var x rune = 'a' // rune is an alias for int32; normally omitted in this statement var y int32 = 'b' fmt.Println(x) fmt.Println(y) diff --git a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/01/main.go b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/01/main.go index bac33089..562f797a 100644 --- a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/01/main.go +++ b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/01/main.go @@ -13,14 +13,14 @@ func main() { defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - quote := new(QuoteResponse) + quote := new(quoteResponse) xml.Unmarshal(body, "e) fmt.Printf("%s: %.2f", quote.Name, quote.LastPrice) } -type QuoteResponse struct { +type quoteResponse struct { Status string Name string LastPrice float32 diff --git a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/02/main.go b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/02/main.go index 5a1f257e..171a116f 100644 --- a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/02/main.go +++ b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/02/main.go @@ -29,7 +29,7 @@ func main() { defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - quote := new(QuoteResponse) + quote := new(quoteResponse) xml.Unmarshal(body, "e) fmt.Printf("%s: $%.2f\n", quote.Name, quote.LastPrice) @@ -40,7 +40,7 @@ func main() { fmt.Printf("Execution Time: %s", elapsed) } -type QuoteResponse struct { +type quoteResponse struct { Status string Name string LastPrice float32 diff --git a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/03/main.go b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/03/main.go index be08026a..677d85e8 100644 --- a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/03/main.go +++ b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/03/main.go @@ -32,7 +32,7 @@ func main() { defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - quote := new(QuoteResponse) + quote := new(quoteResponse) xml.Unmarshal(body, "e) fmt.Printf("%s: $%.2f\n", quote.Name, quote.LastPrice) @@ -48,7 +48,7 @@ func main() { fmt.Printf("Execution Time: %s", elapsed) } -type QuoteResponse struct { +type quoteResponse struct { Status string Name string LastPrice float32 diff --git a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/04/main.go b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/04/main.go index bd7ddb9c..74f7edc5 100644 --- a/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/04/main.go +++ b/22_go-routines/old/01_concurrency_PS/02_stock-symbol-lookup/04/main.go @@ -34,7 +34,7 @@ func main() { defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - quote := new(QuoteResponse) + quote := new(quoteResponse) xml.Unmarshal(body, "e) fmt.Printf("%s: $%.2f\n", quote.Name, quote.LastPrice) @@ -50,7 +50,7 @@ func main() { fmt.Printf("Execution Time: %s", elapsed) } -type QuoteResponse struct { +type quoteResponse struct { Status string Name string LastPrice float32 diff --git a/22_go-routines/old/01_concurrency_PS/03_file-watcher/main.go b/22_go-routines/old/01_concurrency_PS/03_file-watcher/main.go index 57e2172c..a88e7e2f 100644 --- a/22_go-routines/old/01_concurrency_PS/03_file-watcher/main.go +++ b/22_go-routines/old/01_concurrency_PS/03_file-watcher/main.go @@ -26,14 +26,14 @@ func main() { reader := csv.NewReader(strings.NewReader(data)) records, _ := reader.ReadAll() for _, r := range records { - invoice := new(Invoice) + invoice := new(invoice) invoice.Number = r[0] invoice.Amount, _ = strconv.ParseFloat(r[1], 64) invoice.PurchaseOrderNumber, _ = strconv.Atoi(r[2]) unixTime, _ := strconv.ParseInt(r[3], 10, 64) invoice.InvoiceDate = time.Unix(unixTime, 0) - fmt.Printf("Received Invoice '%v' for $%.2f and submitted for processing\n", invoice.Number, invoice.Amount) + fmt.Printf("Received invoice '%v' for $%.2f and submitted for processing\n", invoice.Number, invoice.Amount) } }(string(data)) } @@ -42,7 +42,7 @@ func main() { } } -type Invoice struct { +type invoice struct { Number string Amount float64 PurchaseOrderNumber int diff --git a/22_go-routines/old/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go b/22_go-routines/old/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go index 1c460ecf..2f58c399 100644 --- a/22_go-routines/old/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go +++ b/22_go-routines/old/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go @@ -6,8 +6,8 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) select { case receivedMsg := <-msgCh: @@ -20,15 +20,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } /* 3.5.1 - demo setup @@ -40,18 +40,18 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) - msg := Message{ + msg := message{ To: []string{"bilbo@underhill.me"}, From: "gandalf@whitecouncil.org", Content: "Keep it secret, keep it safe", } - failedMessage := FailedMessage{ - ErrorMessage: "Message intercepted by black rider", - OriginalMessage: Message{}, + failedMessage := failedMessage{ + ErrorMessage: "message intercepted by black rider", + OriginalMessage: message{}, } msgCh <- msg @@ -62,15 +62,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ @@ -83,10 +83,10 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) - msg := Message{ + msg := message{ To: []string{"bilbo@underhill.me"}, From: "gandalf@whitecouncil.org", Content: "Keep it secret, keep it safe", @@ -103,15 +103,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ @@ -124,18 +124,18 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) - msg := Message{ + msg := message{ To: []string{"bilbo@underhill.me"}, From: "gandalf@whitecouncil.org", Content: "Keep it secret, keep it safe", } - failedMessage := FailedMessage{ - ErrorMessage: "Message intercepted by black rider", - OriginalMessage: Message{}, + failedMessage := failedMessage{ + ErrorMessage: "message intercepted by black rider", + OriginalMessage: message{}, } errCh <- failedMessage @@ -149,15 +149,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ @@ -170,18 +170,18 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) - msg := Message{ + msg := message{ To: []string{"bilbo@underhill.me"}, From: "gandalf@whitecouncil.org", Content: "Keep it secret, keep it safe", } - failedMessage := FailedMessage{ - ErrorMessage: "Message intercepted by black rider", - OriginalMessage: Message{}, + failedMessage := failedMessage{ + ErrorMessage: "message intercepted by black rider", + OriginalMessage: message{}, } msgCh <- msg @@ -196,15 +196,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ @@ -217,8 +217,8 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) select { case receivedMsg := <- msgCh: @@ -229,15 +229,15 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ @@ -250,8 +250,8 @@ import ( func main() { - msgCh := make(chan Message, 1) - errCh := make(chan FailedMessage, 1) + msgCh := make(chan message, 1) + errCh := make(chan failedMessage, 1) select { case receivedMsg := <- msgCh: @@ -264,14 +264,14 @@ func main() { } -type Message struct { +type message struct { To []string From string Content string } -type FailedMessage struct { +type failedMessage struct { ErrorMessage string - OriginalMessage Message + OriginalMessage message } */ diff --git a/22_go-routines/old/01_concurrency_PS/06_events_vs_go-routines/complex.go b/22_go-routines/old/01_concurrency_PS/06_events_vs_go-routines/complex.go index 3b78fc00..9604d615 100644 --- a/22_go-routines/old/01_concurrency_PS/06_events_vs_go-routines/complex.go +++ b/22_go-routines/old/01_concurrency_PS/06_events_vs_go-routines/complex.go @@ -5,7 +5,7 @@ import ( ) func main() { - btn := MakeButton() + btn := makeButton() handlerOne := make(chan string, 2) handlerTwo := make(chan string, 2) @@ -27,43 +27,43 @@ func main() { } }() - btn.TriggerEvent("click", "Button clicked!") + btn.TriggerEvent("click", "button clicked!") btn.RemoveEventListener("click", handlerOne) - btn.TriggerEvent("click", "Button clicked again!") + btn.TriggerEvent("click", "button clicked again!") fmt.Scanln() } -type Button struct { +type button struct { eventListeners map[string][]chan string } -func (this *Button) AddEventListener(event string, responseChannel chan string) { - if _, present := this.eventListeners[event]; present { - this.eventListeners[event] = - append(this.eventListeners[event], responseChannel) +func (btn *button) AddEventListener(event string, responseChannel chan string) { + if _, present := btn.eventListeners[event]; present { + btn.eventListeners[event] = + append(btn.eventListeners[event], responseChannel) } else { - this.eventListeners[event] = []chan string{responseChannel} + btn.eventListeners[event] = []chan string{responseChannel} } } -func (this *Button) RemoveEventListener(event string, listenerChannel chan string) { - if _, present := this.eventListeners[event]; present { - for idx, _ := range this.eventListeners[event] { - if this.eventListeners[event][idx] == listenerChannel { - this.eventListeners[event] = append(this.eventListeners[event][:idx], - this.eventListeners[event][idx+1:]...) +func (btn *button) RemoveEventListener(event string, listenerChannel chan string) { + if _, present := btn.eventListeners[event]; present { + for idx := range btn.eventListeners[event] { + if btn.eventListeners[event][idx] == listenerChannel { + btn.eventListeners[event] = append(btn.eventListeners[event][:idx], + btn.eventListeners[event][idx+1:]...) break } } } } -func (this *Button) TriggerEvent(event string, response string) { - if _, present := this.eventListeners[event]; present { - for _, handler := range this.eventListeners[event] { +func (btn *button) TriggerEvent(event string, response string) { + if _, present := btn.eventListeners[event]; present { + for _, handler := range btn.eventListeners[event] { go func(handler chan string) { handler <- response }(handler) @@ -71,8 +71,8 @@ func (this *Button) TriggerEvent(event string, response string) { } } -func MakeButton() *Button { - result := new(Button) +func makeButton() *button { + result := new(button) result.eventListeners = make(map[string][]chan string) return result } diff --git a/22_go-routines/old/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go b/22_go-routines/old/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go index 67e7a91a..2cfe490c 100644 --- a/22_go-routines/old/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go +++ b/22_go-routines/old/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go @@ -4,24 +4,24 @@ import ( "fmt" ) -type PurchaseOrder struct { +type purchaseOrder struct { Number int Value float64 } -func SavePO(po *PurchaseOrder, callbackChannel chan *PurchaseOrder) { +func savePO(po *purchaseOrder, callbackChannel chan *purchaseOrder) { po.Number = 1234 callbackChannel <- po } func main() { - po := new(PurchaseOrder) + po := new(purchaseOrder) po.Value = 42.27 - ch := make(chan *PurchaseOrder) + ch := make(chan *purchaseOrder) - go SavePO(po, ch) + go savePO(po, ch) newPo := <-ch fmt.Printf("PO Number: %d\n", newPo.Number) diff --git a/22_go-routines/old/02_concurrency_CD/02_channels/01/main.go b/22_go-routines/old/02_concurrency_CD/02_channels/01/main.go index 79abad98..5b3922ac 100644 --- a/22_go-routines/old/02_concurrency_CD/02_channels/01/main.go +++ b/22_go-routines/old/02_concurrency_CD/02_channels/01/main.go @@ -26,7 +26,7 @@ func printer(c chan string) { } func main() { - var c chan string = make(chan string) + var c = make(chan string) go pinger(c) go ponger(c) diff --git a/22_go-routines/old/02_concurrency_CD/05/main.go b/22_go-routines/old/02_concurrency_CD/05/main.go index 07c23fbf..06dd3ec3 100644 --- a/22_go-routines/old/02_concurrency_CD/05/main.go +++ b/22_go-routines/old/02_concurrency_CD/05/main.go @@ -20,7 +20,7 @@ func printer(c chan string) { } func main() { - var c chan string = make(chan string) + var c = make(chan string) go pinger(c) go printer(c) diff --git a/22_go-routines/old/02_concurrency_CD/06/main.go b/22_go-routines/old/02_concurrency_CD/06/main.go index cb9e8377..cc3be37b 100644 --- a/22_go-routines/old/02_concurrency_CD/06/main.go +++ b/22_go-routines/old/02_concurrency_CD/06/main.go @@ -26,7 +26,7 @@ func printer(c chan string) { } func main() { - var c chan string = make(chan string) + var c = make(chan string) go pinger(c) go ponger(c) diff --git a/22_go-routines/old/02_concurrency_CD/07/main.go b/22_go-routines/old/02_concurrency_CD/07/main.go index cb9e8377..cc3be37b 100644 --- a/22_go-routines/old/02_concurrency_CD/07/main.go +++ b/22_go-routines/old/02_concurrency_CD/07/main.go @@ -26,7 +26,7 @@ func printer(c chan string) { } func main() { - var c chan string = make(chan string) + var c = make(chan string) go pinger(c) go ponger(c) diff --git a/22_go-routines/old/02_concurrency_CD/09/main.go b/22_go-routines/old/02_concurrency_CD/09/main.go index c630fee2..363d08b0 100644 --- a/22_go-routines/old/02_concurrency_CD/09/main.go +++ b/22_go-routines/old/02_concurrency_CD/09/main.go @@ -27,7 +27,7 @@ func printer(c chan string) { } func main() { - var c chan string = make(chan string) + var c = make(chan string) go ping(c) go pong(c) diff --git a/22_go-routines/old/02_concurrency_CD/10_channels/main.go b/22_go-routines/old/02_concurrency_CD/10_channels/main.go index 64ed8b4c..c6ddb51f 100644 --- a/22_go-routines/old/02_concurrency_CD/10_channels/main.go +++ b/22_go-routines/old/02_concurrency_CD/10_channels/main.go @@ -18,7 +18,7 @@ func printer(c chan int) { } func main() { - var c chan int = make(chan int) + var c = make(chan int) go iterate(c) go printer(c)