diff --git a/01_getting-started/01_helloWorld/firstFile.go b/01_getting-started/01_helloWorld/firstFile.go index f7cc460a..5093f125 100644 --- a/01_getting-started/01_helloWorld/firstFile.go +++ b/01_getting-started/01_helloWorld/firstFile.go @@ -15,4 +15,4 @@ so in my GOPATH you will see it pointing to: GOPATH="/Users/tm002/Documents/go" -*/ \ No newline at end of file +*/ diff --git a/02_package/stringutil/reverse.go b/02_package/stringutil/reverse.go index 0eeabbc3..456b2ace 100644 --- a/02_package/stringutil/reverse.go +++ b/02_package/stringutil/reverse.go @@ -13,4 +13,4 @@ go build go install will place the package inside the pkg directory of the workspace. -*/ \ No newline at end of file +*/ diff --git a/03_variables/01_shorthand/01/main.go b/03_variables/01_shorthand/01/main.go index 55dfb978..62d97b5c 100644 --- a/03_variables/01_shorthand/01/main.go +++ b/03_variables/01_shorthand/01/main.go @@ -19,4 +19,4 @@ func main() { fmt.Printf("%v \n", e) fmt.Printf("%v \n", f) fmt.Printf("%v \n", g) -} \ No newline at end of file +} diff --git a/03_variables/01_shorthand/02/main.go b/03_variables/01_shorthand/02/main.go index f7127b34..c1d374ed 100644 --- a/03_variables/01_shorthand/02/main.go +++ b/03_variables/01_shorthand/02/main.go @@ -19,4 +19,4 @@ func main() { fmt.Printf("%T \n", e) fmt.Printf("%T \n", f) fmt.Printf("%T \n", g) -} \ No newline at end of file +} diff --git a/03_variables/02_var_zero-value/main.go b/03_variables/02_var_zero-value/main.go index d6478be3..c8424a2b 100644 --- a/03_variables/02_var_zero-value/main.go +++ b/03_variables/02_var_zero-value/main.go @@ -15,4 +15,4 @@ func main() { fmt.Printf("%v \n", d) fmt.Println() -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/03_init-many-at-once/var.go b/03_variables/03_less-emphasis/03_init-many-at-once/var.go index ddc272f8..93d2d148 100644 --- a/03_variables/03_less-emphasis/03_init-many-at-once/var.go +++ b/03_variables/03_less-emphasis/03_init-many-at-once/var.go @@ -8,4 +8,4 @@ func main() { var a, b, c int = 1, 2, 3 fmt.Println(message, a, b, c) -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/04_infer-type/var.go b/03_variables/03_less-emphasis/04_infer-type/var.go index 413cfe78..72adb8f1 100644 --- a/03_variables/03_less-emphasis/04_infer-type/var.go +++ b/03_variables/03_less-emphasis/04_infer-type/var.go @@ -8,4 +8,4 @@ func main() { var a, b, c = 1, 2, 3 fmt.Println(message, a, b, c) -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/05_infer-mixed-up-types/var.go b/03_variables/03_less-emphasis/05_infer-mixed-up-types/var.go index 4de787f8..fc3e7c94 100644 --- a/03_variables/03_less-emphasis/05_infer-mixed-up-types/var.go +++ b/03_variables/03_less-emphasis/05_infer-mixed-up-types/var.go @@ -8,4 +8,4 @@ func main() { var a, b, c = 1, false, 3 fmt.Println(message, a, b, c) -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/06_init-shorthand/var.go b/03_variables/03_less-emphasis/06_init-shorthand/var.go index 3519714f..c272b765 100644 --- a/03_variables/03_less-emphasis/06_init-shorthand/var.go +++ b/03_variables/03_less-emphasis/06_init-shorthand/var.go @@ -11,4 +11,4 @@ func main() { e := true fmt.Println(message, a, b, c, d, e) -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/07_all-together/variables.go b/03_variables/03_less-emphasis/07_all-together/variables.go index e7a69c58..eac90fe2 100644 --- a/03_variables/03_less-emphasis/07_all-together/variables.go +++ b/03_variables/03_less-emphasis/07_all-together/variables.go @@ -3,19 +3,19 @@ package main import "fmt" var a string = "this is stored in the variable a" // package scope -var b, c string = "stored in b", "stored in c" // package scope -var d string // package scope +var b, c string = "stored in b", "stored in c" // package scope +var d string // package scope func main() { d = "stored in d" // declaration above; assignment here; package scope - var e int = 42 // function scope - subsequent variables have same package scope: + var e int = 42 // function scope - subsequent variables have same package scope: f := 43 g := "stored in g" h, i := "stored in h", "stored in i" j, k, l, m := 44.7, true, false, 'm' // single quotes - n := "n" // double quotes - o := `o` // back ticks + n := "n" // double quotes + o := `o` // back ticks fmt.Println("a - ", a) fmt.Println("b - ", b) @@ -32,4 +32,4 @@ func main() { fmt.Println("m - ", m) fmt.Println("n - ", n) fmt.Println("o - ", o) -} \ No newline at end of file +} diff --git a/03_variables/03_less-emphasis/08_exercise_your-name/01_oneSolution/myNameVar.go b/03_variables/03_less-emphasis/08_exercise_your-name/01_oneSolution/myNameVar.go index a95ca700..199fc98b 100644 --- a/03_variables/03_less-emphasis/08_exercise_your-name/01_oneSolution/myNameVar.go +++ b/03_variables/03_less-emphasis/08_exercise_your-name/01_oneSolution/myNameVar.go @@ -4,6 +4,6 @@ import "fmt" var name string = "Todd" -func main(){ +func main() { fmt.Println("Hello ", name) } diff --git a/03_variables/03_less-emphasis/08_exercise_your-name/02_anotherSolution/myNameVar.go b/03_variables/03_less-emphasis/08_exercise_your-name/02_anotherSolution/myNameVar.go index 6ffe9561..dc38f210 100644 --- a/03_variables/03_less-emphasis/08_exercise_your-name/02_anotherSolution/myNameVar.go +++ b/03_variables/03_less-emphasis/08_exercise_your-name/02_anotherSolution/myNameVar.go @@ -2,7 +2,7 @@ package main import "fmt" -func main(){ +func main() { var name string = "Todd" fmt.Println("Hello ", name) } diff --git a/03_variables/03_less-emphasis/08_exercise_your-name/03_anotherSolution/myNameVar.go b/03_variables/03_less-emphasis/08_exercise_your-name/03_anotherSolution/myNameVar.go index 1a4ec5eb..673e21a7 100644 --- a/03_variables/03_less-emphasis/08_exercise_your-name/03_anotherSolution/myNameVar.go +++ b/03_variables/03_less-emphasis/08_exercise_your-name/03_anotherSolution/myNameVar.go @@ -2,7 +2,7 @@ package main import "fmt" -func main(){ +func main() { name := "Todd" fmt.Println("Hello ", name) } diff --git a/03_variables/03_less-emphasis/08_exercise_your-name/04_anotherSolution/myNameVar.go b/03_variables/03_less-emphasis/08_exercise_your-name/04_anotherSolution/myNameVar.go index 15e9251e..4f03a0f3 100644 --- a/03_variables/03_less-emphasis/08_exercise_your-name/04_anotherSolution/myNameVar.go +++ b/03_variables/03_less-emphasis/08_exercise_your-name/04_anotherSolution/myNameVar.go @@ -2,7 +2,7 @@ package main import "fmt" -func main(){ +func main() { name := `Todd` // back-ticks work like double-quotes fmt.Println("Hello ", name) } diff --git a/04_scope/02_block-scope/02_closure/01/main.go b/04_scope/02_block-scope/02_closure/01/main.go index b4c60109..b6aefb89 100644 --- a/04_scope/02_block-scope/02_closure/01/main.go +++ b/04_scope/02_block-scope/02_closure/01/main.go @@ -11,4 +11,4 @@ func main() { fmt.Println(y) } // fmt.Println(y) // outside scope of y -} \ No newline at end of file +} diff --git a/04_scope/02_block-scope/02_closure/02/main.go b/04_scope/02_block-scope/02_closure/02/main.go index a6ba7f51..9213136a 100644 --- a/04_scope/02_block-scope/02_closure/02/main.go +++ b/04_scope/02_block-scope/02_closure/02/main.go @@ -18,4 +18,4 @@ func main() { closure helps us limit the scope of variables used by multiple functions without closure, for two or more funcs to have access to the same variable, that variable would need to be package scope -*/ \ No newline at end of file +*/ diff --git a/04_scope/02_block-scope/02_closure/03/main.go b/04_scope/02_block-scope/02_closure/03/main.go index 2ed91f07..54e0757b 100644 --- a/04_scope/02_block-scope/02_closure/03/main.go +++ b/04_scope/02_block-scope/02_closure/03/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { x := 0 - increment := func () int { + increment := func() int { x++ return x } @@ -22,4 +22,4 @@ a function without a name func expression assigning a func to a variable -*/ \ No newline at end of file +*/ diff --git a/04_scope/03_order-matters/main.go b/04_scope/03_order-matters/main.go index 7e8e83ca..c0fb1ffc 100644 --- a/04_scope/03_order-matters/main.go +++ b/04_scope/03_order-matters/main.go @@ -7,4 +7,5 @@ func main() { fmt.Println(y) x := 42 } -var y = 42 \ No newline at end of file + +var y = 42 diff --git a/05_blank-identifier/01_invalid-code/main.go b/05_blank-identifier/01_invalid-code/main.go index efe899b5..cfd0a252 100644 --- a/05_blank-identifier/01_invalid-code/main.go +++ b/05_blank-identifier/01_invalid-code/main.go @@ -7,4 +7,4 @@ func main() { b := "stored in b" fmt.Println("a - ", a) // b is not being used - invalid code -} \ No newline at end of file +} diff --git a/05_blank-identifier/02_http-get_example/01_with-error-checking/main.go b/05_blank-identifier/02_http-get_example/01_with-error-checking/main.go index 625ab2d1..3f2a664b 100644 --- a/05_blank-identifier/02_http-get_example/01_with-error-checking/main.go +++ b/05_blank-identifier/02_http-get_example/01_with-error-checking/main.go @@ -1,10 +1,10 @@ package main import ( - "net/http" - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" + "net/http" ) func main() { @@ -18,4 +18,4 @@ func main() { log.Fatal(err) } fmt.Printf("%s", page) -} \ No newline at end of file +} diff --git a/05_blank-identifier/02_http-get_example/02_no-error-checking/main.go b/05_blank-identifier/02_http-get_example/02_no-error-checking/main.go index 297db5bf..97dcf97a 100644 --- a/05_blank-identifier/02_http-get_example/02_no-error-checking/main.go +++ b/05_blank-identifier/02_http-get_example/02_no-error-checking/main.go @@ -1,9 +1,9 @@ package main import ( - "net/http" - "io/ioutil" "fmt" + "io/ioutil" + "net/http" ) func main() { @@ -11,4 +11,4 @@ func main() { page, _ := ioutil.ReadAll(res.Body) res.Body.Close() fmt.Printf("%s", page) -} \ No newline at end of file +} diff --git a/06_constants/01_constant/main.go b/06_constants/01_constant/main.go index dfc2a053..d82460b4 100644 --- a/06_constants/01_constant/main.go +++ b/06_constants/01_constant/main.go @@ -13,4 +13,3 @@ func main() { } // a CONSTANT is a simple unchanging value - diff --git a/06_constants/03_iota/main.go b/06_constants/03_iota/main.go index e94933ab..76f37266 100644 --- a/06_constants/03_iota/main.go +++ b/06_constants/03_iota/main.go @@ -3,13 +3,13 @@ package main import "fmt" const ( - A = iota // 0 - B = iota // 1 - C = iota // 2 + A = iota // 0 + B = iota // 1 + C = iota // 2 ) func main() { fmt.Println(A) fmt.Println(B) fmt.Println(C) -} \ No newline at end of file +} diff --git a/06_constants/04_iota/main.go b/06_constants/04_iota/main.go index 63f49e2a..362735e8 100644 --- a/06_constants/04_iota/main.go +++ b/06_constants/04_iota/main.go @@ -3,13 +3,13 @@ package main import "fmt" const ( - A = iota // 0 - B // 1 - C // 2 + A = iota // 0 + B // 1 + C // 2 ) func main() { fmt.Println(A) fmt.Println(B) fmt.Println(C) -} \ No newline at end of file +} diff --git a/06_constants/05_iota/main.go b/06_constants/05_iota/main.go index 26f00f55..bbbc1fb3 100644 --- a/06_constants/05_iota/main.go +++ b/06_constants/05_iota/main.go @@ -3,15 +3,15 @@ package main import "fmt" const ( - A = iota // 0 - B // 1 - C // 2 + A = iota // 0 + B // 1 + C // 2 ) const ( - D = iota // 0 - E // 1 - F // 2 + D = iota // 0 + E // 1 + F // 2 ) func main() { @@ -21,4 +21,4 @@ func main() { fmt.Println(D) fmt.Println(E) fmt.Println(F) -} \ No newline at end of file +} diff --git a/06_constants/06_iota/main.go b/06_constants/06_iota/main.go index ea5b0b6b..e9f169ca 100644 --- a/06_constants/06_iota/main.go +++ b/06_constants/06_iota/main.go @@ -3,7 +3,7 @@ package main import "fmt" const ( - _ = iota // 0 + _ = iota // 0 B = iota * 10 // 1 * 10 C = iota * 10 // 2 * 10 ) @@ -11,4 +11,4 @@ const ( func main() { fmt.Println(B) fmt.Println(C) -} \ No newline at end of file +} diff --git a/06_constants/07_iota/main.go b/06_constants/07_iota/main.go index d8bd8af7..f405ef2e 100644 --- a/06_constants/07_iota/main.go +++ b/06_constants/07_iota/main.go @@ -3,7 +3,7 @@ package main import "fmt" const ( - _ = iota // 0 + _ = iota // 0 KB = 1 << (iota * 10) // 1 << (1 * 10) MB = 1 << (iota * 10) // 1 << (2 * 10) GB = 1 << (iota * 10) // 1 << (3 * 10) @@ -20,4 +20,4 @@ func main() { fmt.Printf("%d\n", GB) fmt.Printf("%b\t", TB) fmt.Printf("%d\n", TB) -} \ No newline at end of file +} diff --git a/07_memory-address/01_showing-address/main.go b/07_memory-address/01_showing-address/main.go index 8f74c84e..0077e212 100644 --- a/07_memory-address/01_showing-address/main.go +++ b/07_memory-address/01_showing-address/main.go @@ -9,4 +9,4 @@ func main() { fmt.Println("a - ", a) fmt.Println("a's memory address - ", &a) fmt.Printf("%d \n", &a) -} \ No newline at end of file +} diff --git a/07_memory-address/02_using-address/main.go b/07_memory-address/02_using-address/main.go index c13515f2..67524cae 100644 --- a/07_memory-address/02_using-address/main.go +++ b/07_memory-address/02_using-address/main.go @@ -4,10 +4,10 @@ import "fmt" const metersToYards float64 = 1.09361 -func main(){ -var meters float64 -fmt.Print("Enter meters swam: ") -fmt.Scan(&meters) -yards := meters * metersToYards -fmt.Println(meters, " meters is ", yards, " yards.") -} \ No newline at end of file +func main() { + var meters float64 + fmt.Print("Enter meters swam: ") + fmt.Scan(&meters) + yards := meters * metersToYards + fmt.Println(meters, " meters is ", yards, " yards.") +} diff --git a/08_pointers/01_referencing/main.go b/08_pointers/01_referencing/main.go index 9166f807..c84d0c1a 100644 --- a/08_pointers/01_referencing/main.go +++ b/08_pointers/01_referencing/main.go @@ -11,7 +11,6 @@ func main() { fmt.Println(a) fmt.Println(&a) - var b *int = &a fmt.Println(b) @@ -19,4 +18,4 @@ func main() { // the above code makes b a pointer to the memory address where an int is stored // b is of type "int pointer" // *int -- the * is part of the type -- b is of type *int -} \ No newline at end of file +} diff --git a/08_pointers/02_dereferencing/main.go b/08_pointers/02_dereferencing/main.go index 53f3aedb..e9f7e906 100644 --- a/08_pointers/02_dereferencing/main.go +++ b/08_pointers/02_dereferencing/main.go @@ -6,12 +6,12 @@ func main() { a := 43 - fmt.Println(a) // 43 + fmt.Println(a) // 43 fmt.Println(&a) // 0x20818a220 var b *int = &a - fmt.Println(b) // 0x20818a220 - fmt.Println(*b) // 43 + fmt.Println(b) // 0x20818a220 + fmt.Println(*b) // 43 // b is an int pointer; // b points to the memory address where an int is stored diff --git a/08_pointers/03_using-pointers/main.go b/08_pointers/03_using-pointers/main.go index 9eda9b49..e06276c1 100644 --- a/08_pointers/03_using-pointers/main.go +++ b/08_pointers/03_using-pointers/main.go @@ -6,14 +6,14 @@ func main() { a := 43 - fmt.Println(a) // 43 + fmt.Println(a) // 43 fmt.Println(&a) // 0x20818a220 var b *int = &a - fmt.Println(b) // 0x20818a220 - fmt.Println(*b) // 43 + fmt.Println(b) // 0x20818a220 + fmt.Println(*b) // 43 - *b = 42 // b says, "The value at this address, change it to 42" + *b = 42 // b says, "The value at this address, change it to 42" fmt.Println(a) // 42 // this is useful diff --git a/08_pointers/04_using-pointers/01_no-pointer/02_see-the-addresses/main.go b/08_pointers/04_using-pointers/01_no-pointer/02_see-the-addresses/main.go index 069aefcf..e2548ca6 100644 --- a/08_pointers/04_using-pointers/01_no-pointer/02_see-the-addresses/main.go +++ b/08_pointers/04_using-pointers/01_no-pointer/02_see-the-addresses/main.go @@ -3,15 +3,15 @@ package main import "fmt" func zero(z int) { - fmt.Printf("%p\n",&z) // address in func zero - fmt.Println(&z) // address in func zero + fmt.Printf("%p\n", &z) // address in func zero + fmt.Println(&z) // address in func zero z = 0 } func main() { x := 5 - fmt.Printf("%p\n",&x) // address in main - fmt.Println(&x) // address in main + fmt.Printf("%p\n", &x) // address in main + fmt.Println(&x) // address in main zero(x) fmt.Println(x) // x is still 5 } diff --git a/09_remainder/main.go b/09_remainder/main.go index f990fca4..e5ab4057 100644 --- a/09_remainder/main.go +++ b/09_remainder/main.go @@ -12,10 +12,10 @@ func main() { } for i := 1; i < 70; i++ { - if i % 2 == 1 { + if i%2 == 1 { fmt.Println("Odd") } else { fmt.Println("Even") } } -} \ No newline at end of file +} diff --git a/10_for-loop/01_init-condition-post/main.go b/10_for-loop/01_init-condition-post/main.go index 7fc1711e..995f1f45 100644 --- a/10_for-loop/01_init-condition-post/main.go +++ b/10_for-loop/01_init-condition-post/main.go @@ -6,4 +6,4 @@ func main() { for i := 0; i <= 100; i++ { fmt.Println(i) } -} \ No newline at end of file +} diff --git a/10_for-loop/02_nested/main.go b/10_for-loop/02_nested/main.go index 3ca26bde..ff14ecbf 100644 --- a/10_for-loop/02_nested/main.go +++ b/10_for-loop/02_nested/main.go @@ -8,4 +8,4 @@ func main() { fmt.Println(i, " - ", j) } } -} \ No newline at end of file +} diff --git a/10_for-loop/03_for-condition-while-ish/main.go b/10_for-loop/03_for-condition-while-ish/main.go index 7cfb3586..91d37e92 100644 --- a/10_for-loop/03_for-condition-while-ish/main.go +++ b/10_for-loop/03_for-condition-while-ish/main.go @@ -8,4 +8,4 @@ func main() { fmt.Println(i) i++ } -} \ No newline at end of file +} diff --git a/10_for-loop/04_for_no-condition/main.go b/10_for-loop/04_for_no-condition/main.go index 631b73d2..5121a6e6 100644 --- a/10_for-loop/04_for_no-condition/main.go +++ b/10_for-loop/04_for_no-condition/main.go @@ -2,7 +2,6 @@ package main import "fmt" - func main() { i := 0 for { diff --git a/10_for-loop/05_for_break/main.go b/10_for-loop/05_for_break/main.go index 157a921a..6b36645e 100644 --- a/10_for-loop/05_for_break/main.go +++ b/10_for-loop/05_for_break/main.go @@ -2,7 +2,6 @@ package main import "fmt" - func main() { i := 0 for { diff --git a/10_for-loop/06_for_continue/main.go b/10_for-loop/06_for_continue/main.go index 6d7f531b..32ca3209 100644 --- a/10_for-loop/06_for_continue/main.go +++ b/10_for-loop/06_for_continue/main.go @@ -2,12 +2,11 @@ package main import "fmt" - func main() { i := 0 for { i++ - if i % 2 == 0 { + if i%2 == 0 { continue } fmt.Println(i) @@ -15,4 +14,4 @@ func main() { break } } -} \ No newline at end of file +} diff --git a/11_switch-statements/01_switch/main.go b/11_switch-statements/01_switch/main.go index d1e10de5..e7accb76 100644 --- a/11_switch-statements/01_switch/main.go +++ b/11_switch-statements/01_switch/main.go @@ -20,4 +20,4 @@ func main() { fallthrough is optional -- you can specify fallthrough by explicitly stating it -- break isn't needed like in other languages - */ \ No newline at end of file +*/ diff --git a/11_switch-statements/03_multiple-evals/main.go b/11_switch-statements/03_multiple-evals/main.go index cd547fa3..f99f1da5 100644 --- a/11_switch-statements/03_multiple-evals/main.go +++ b/11_switch-statements/03_multiple-evals/main.go @@ -11,4 +11,4 @@ func main() { case "Julian", "Sushant": fmt.Println("Wassup Julian / Sushant") } -} \ No newline at end of file +} diff --git a/11_switch-statements/04_no-expression/main.go b/11_switch-statements/04_no-expression/main.go index ce31ce00..b7c1dba4 100644 --- a/11_switch-statements/04_no-expression/main.go +++ b/11_switch-statements/04_no-expression/main.go @@ -29,4 +29,4 @@ func main() { -- if no expression provided, go checks for the first case that evals to true -- makes the switch operate like if/if else/else cases can be expressions -*/ \ No newline at end of file +*/ diff --git a/11_switch-statements/05_on-type/type.go b/11_switch-statements/05_on-type/type.go index 6d5c3498..0c0622a3 100644 --- a/11_switch-statements/05_on-type/type.go +++ b/11_switch-statements/05_on-type/type.go @@ -13,7 +13,7 @@ type Contact struct { // we'll learn more about interfaces later func SwitchOnType(x interface{}) { - switch x.(type) { // this is an assert; asserting, "x is of this type" + switch x.(type) { // this is an assert; asserting, "x is of this type" case int: fmt.Println("int") case string: @@ -33,4 +33,4 @@ func main() { SwitchOnType(t) SwitchOnType(t.greeting) SwitchOnType(t.name) -} \ No newline at end of file +} diff --git a/12_conditionals/03_init-statement/main.go b/12_conditionals/03_init-statement/main.go index 8e30b72c..3a8f2d63 100644 --- a/12_conditionals/03_init-statement/main.go +++ b/12_conditionals/03_init-statement/main.go @@ -10,4 +10,4 @@ func main() { fmt.Println(food) } -} \ No newline at end of file +} diff --git a/12_conditionals/04_init-statement_error_invalid-code/main.go b/12_conditionals/04_init-statement_error_invalid-code/main.go index a6d803b9..b97427da 100644 --- a/12_conditionals/04_init-statement_error_invalid-code/main.go +++ b/12_conditionals/04_init-statement_error_invalid-code/main.go @@ -12,4 +12,4 @@ func main() { fmt.Println(food) -} \ No newline at end of file +} diff --git a/12_conditionals/08_divisibleByThree/main.go b/12_conditionals/08_divisibleByThree/main.go index 85e34812..9fd744c4 100644 --- a/12_conditionals/08_divisibleByThree/main.go +++ b/12_conditionals/08_divisibleByThree/main.go @@ -8,4 +8,4 @@ func main() { fmt.Println(i) } } -} \ No newline at end of file +} diff --git a/13_exercise-solutions/01_whatRemains/main.go b/13_exercise-solutions/01_whatRemains/main.go index 71361c13..cb165ddb 100644 --- a/13_exercise-solutions/01_whatRemains/main.go +++ b/13_exercise-solutions/01_whatRemains/main.go @@ -8,5 +8,5 @@ func main() { fmt.Scanln(&smaller) fmt.Print("Enter a second larger number: ") fmt.Scanln(&larger) - fmt.Println(larger%smaller) + fmt.Println(larger % smaller) } diff --git a/13_exercise-solutions/02_even-numbers/main.go b/13_exercise-solutions/02_even-numbers/main.go index 6d272b9e..ba231250 100644 --- a/13_exercise-solutions/02_even-numbers/main.go +++ b/13_exercise-solutions/02_even-numbers/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { for i := 1; i <= 100; i++ { - if i % 2 == 0 { + if i%2 == 0 { fmt.Println(i) } } diff --git a/13_exercise-solutions/03_fizzBuzz/main.go b/13_exercise-solutions/03_fizzBuzz/main.go index 5dbc7a75..e22631a7 100644 --- a/13_exercise-solutions/03_fizzBuzz/main.go +++ b/13_exercise-solutions/03_fizzBuzz/main.go @@ -14,4 +14,4 @@ func main() { fmt.Println(i) } } -} \ No newline at end of file +} diff --git a/13_exercise-solutions/04_threeFive/main.go b/13_exercise-solutions/04_threeFive/main.go index 8922ef22..eaacdadc 100644 --- a/13_exercise-solutions/04_threeFive/main.go +++ b/13_exercise-solutions/04_threeFive/main.go @@ -20,4 +20,4 @@ If we list all the natural numbers below 10 that are multiples of 3 or 5, we get The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. -*/ \ No newline at end of file +*/ diff --git a/13_exercise-solutions/05_benchMark/bm_test.go b/13_exercise-solutions/05_benchMark/bm_test.go index 73bb6451..05ab8555 100644 --- a/13_exercise-solutions/05_benchMark/bm_test.go +++ b/13_exercise-solutions/05_benchMark/bm_test.go @@ -1,8 +1,8 @@ package main import ( - "testing" "fmt" + "testing" ) func BenchmarkHello(b *testing.B) { diff --git a/13_exercise-solutions/06_benchMark/bm_test.go b/13_exercise-solutions/06_benchMark/bm_test.go index 869c76a8..c71e711c 100644 --- a/13_exercise-solutions/06_benchMark/bm_test.go +++ b/13_exercise-solutions/06_benchMark/bm_test.go @@ -1,8 +1,8 @@ package main import ( - "testing" "fmt" + "testing" ) func BenchmarkHello(b *testing.B) { diff --git a/14_functions/01_main/main.go b/14_functions/01_main/main.go index 9d402b86..c58b6d95 100644 --- a/14_functions/01_main/main.go +++ b/14_functions/01_main/main.go @@ -6,4 +6,4 @@ func main() { fmt.Println("Hello world!") } -// main is the entry point to your program \ No newline at end of file +// main is the entry point to your program diff --git a/14_functions/02_param-arg/main.go b/14_functions/02_param-arg/main.go index a44bd193..a1577972 100644 --- a/14_functions/02_param-arg/main.go +++ b/14_functions/02_param-arg/main.go @@ -10,5 +10,6 @@ func main() { func greet(name string) { fmt.Println(name) } + // greet is declared with a parameter -// when calling greet, pass in an argument \ No newline at end of file +// when calling greet, pass in an argument diff --git a/14_functions/03_two-params/02/main.go b/14_functions/03_two-params/02/main.go index 2cb7e978..5340847b 100644 --- a/14_functions/03_two-params/02/main.go +++ b/14_functions/03_two-params/02/main.go @@ -8,4 +8,4 @@ func main() { func greet(fname, lname string) { fmt.Println(fname, lname) -} \ No newline at end of file +} diff --git a/14_functions/05_return-naming/main.go b/14_functions/05_return-naming/main.go index 0c87e621..a43177f0 100644 --- a/14_functions/05_return-naming/main.go +++ b/14_functions/05_return-naming/main.go @@ -9,4 +9,4 @@ func main() { func greet(fname string, lname string) (s string) { s = fmt.Sprint(fname, lname) return -} \ No newline at end of file +} diff --git a/14_functions/06_return-multiple/main.go b/14_functions/06_return-multiple/main.go index 43c5346e..5ab061ba 100644 --- a/14_functions/06_return-multiple/main.go +++ b/14_functions/06_return-multiple/main.go @@ -8,4 +8,4 @@ func main() { func greet(fname, lname string) (string, string) { return fmt.Sprint(fname, lname), fmt.Sprint(lname, fname) -} \ No newline at end of file +} diff --git a/14_functions/07_variadic-params/main.go b/14_functions/07_variadic-params/main.go index c38ebe4b..8dd6e501 100644 --- a/14_functions/07_variadic-params/main.go +++ b/14_functions/07_variadic-params/main.go @@ -13,4 +13,4 @@ func average(sf ...float64) float64 { total += v } return total / float64(len(sf)) -} \ No newline at end of file +} diff --git a/14_functions/08_variadic-args/main.go b/14_functions/08_variadic-args/main.go index 00678ab6..60952efd 100644 --- a/14_functions/08_variadic-args/main.go +++ b/14_functions/08_variadic-args/main.go @@ -14,4 +14,4 @@ func average(sf ...float64) float64 { total += v } return total / float64(len(sf)) -} \ No newline at end of file +} diff --git a/14_functions/09_slice-param-arg/main.go b/14_functions/09_slice-param-arg/main.go index 997b869c..8038b68c 100644 --- a/14_functions/09_slice-param-arg/main.go +++ b/14_functions/09_slice-param-arg/main.go @@ -14,4 +14,4 @@ func average(sf []float64) float64 { total += v } return total / float64(len(sf)) -} \ No newline at end of file +} diff --git a/14_functions/10_func-expression/01_before-func-expression/main.go b/14_functions/10_func-expression/01_before-func-expression/main.go index 4f1cc54e..4a3afb94 100644 --- a/14_functions/10_func-expression/01_before-func-expression/main.go +++ b/14_functions/10_func-expression/01_before-func-expression/main.go @@ -8,4 +8,4 @@ func greeting() { func main() { greeting() -} \ No newline at end of file +} diff --git a/14_functions/10_func-expression/02_func-expression/main.go b/14_functions/10_func-expression/02_func-expression/main.go index 525228e2..64d6f8e7 100644 --- a/14_functions/10_func-expression/02_func-expression/main.go +++ b/14_functions/10_func-expression/02_func-expression/main.go @@ -9,4 +9,4 @@ func main() { } greeting() -} \ No newline at end of file +} diff --git a/14_functions/10_func-expression/03_func-expression_shows-type/main.go b/14_functions/10_func-expression/03_func-expression_shows-type/main.go index 53e3c631..4de41fa4 100644 --- a/14_functions/10_func-expression/03_func-expression_shows-type/main.go +++ b/14_functions/10_func-expression/03_func-expression_shows-type/main.go @@ -10,4 +10,4 @@ func main() { greeting() fmt.Printf("%T\n", greeting) -} \ No newline at end of file +} diff --git a/14_functions/11_closure/01/main.go b/14_functions/11_closure/01/main.go index b4c60109..b6aefb89 100644 --- a/14_functions/11_closure/01/main.go +++ b/14_functions/11_closure/01/main.go @@ -11,4 +11,4 @@ func main() { fmt.Println(y) } // fmt.Println(y) // outside scope of y -} \ No newline at end of file +} diff --git a/14_functions/11_closure/02/main.go b/14_functions/11_closure/02/main.go index a6ba7f51..9213136a 100644 --- a/14_functions/11_closure/02/main.go +++ b/14_functions/11_closure/02/main.go @@ -18,4 +18,4 @@ func main() { closure helps us limit the scope of variables used by multiple functions without closure, for two or more funcs to have access to the same variable, that variable would need to be package scope -*/ \ No newline at end of file +*/ diff --git a/14_functions/11_closure/03/main.go b/14_functions/11_closure/03/main.go index 2ed91f07..54e0757b 100644 --- a/14_functions/11_closure/03/main.go +++ b/14_functions/11_closure/03/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { x := 0 - increment := func () int { + increment := func() int { x++ return x } @@ -22,4 +22,4 @@ a function without a name func expression assigning a func to a variable -*/ \ No newline at end of file +*/ diff --git a/14_functions/15_passing-by-value/01_int/main.go b/14_functions/15_passing-by-value/01_int/main.go index 15ab2c88..380e89c2 100644 --- a/14_functions/15_passing-by-value/01_int/main.go +++ b/14_functions/15_passing-by-value/01_int/main.go @@ -14,4 +14,4 @@ func changeMe(z int) { } // when changeMe is called on line 8 -// the value 44 is being passed as an argument \ No newline at end of file +// the value 44 is being passed as an argument diff --git a/14_functions/15_passing-by-value/02_int-pointer/main.go b/14_functions/15_passing-by-value/02_int-pointer/main.go index 62e4f97a..28871dab 100644 --- a/14_functions/15_passing-by-value/02_int-pointer/main.go +++ b/14_functions/15_passing-by-value/02_int-pointer/main.go @@ -10,13 +10,13 @@ func main() { changeMe(&age) fmt.Println(&age) //0x82023c080 - fmt.Println(age) //24 + fmt.Println(age) //24 } func changeMe(z *int) { - fmt.Println(z) // 0x82023c080 + fmt.Println(z) // 0x82023c080 fmt.Println(*z) // 44 *z = 24 - fmt.Println(z) // 0x82023c080 + fmt.Println(z) // 0x82023c080 fmt.Println(*z) // 24 } diff --git a/14_functions/15_passing-by-value/04_string-pointer/main.go b/14_functions/15_passing-by-value/04_string-pointer/main.go index b17ed8d9..643f79f4 100644 --- a/14_functions/15_passing-by-value/04_string-pointer/main.go +++ b/14_functions/15_passing-by-value/04_string-pointer/main.go @@ -10,13 +10,13 @@ func main() { changeMe(&name) fmt.Println(&name) //0x82023c080 - fmt.Println(name) //Rocky + fmt.Println(name) //Rocky } func changeMe(z *string) { - fmt.Println(z) // 0x82023c080 + fmt.Println(z) // 0x82023c080 fmt.Println(*z) // Todd *z = "Rocky" - fmt.Println(z) // 0x82023c080 + fmt.Println(z) // 0x82023c080 fmt.Println(*z) // Rocky } diff --git a/14_functions/15_passing-by-value/05_REFERENCE-TYPE/main.go b/14_functions/15_passing-by-value/05_REFERENCE-TYPE/main.go index 49452dd0..c1abbfab 100644 --- a/14_functions/15_passing-by-value/05_REFERENCE-TYPE/main.go +++ b/14_functions/15_passing-by-value/05_REFERENCE-TYPE/main.go @@ -23,4 +23,4 @@ a pointer to the data (inside an array), the length, and the capacity, and until the slice is nil. For slices, maps, and channels, make initializes the internal data structure and prepares the value for use. */ -// https://golang.org/doc/effective_go.html#allocation_make \ No newline at end of file +// https://golang.org/doc/effective_go.html#allocation_make diff --git a/14_functions/15_passing-by-value/06_REFERENCE-TYPE/main.go b/14_functions/15_passing-by-value/06_REFERENCE-TYPE/main.go index b8243a4f..fed22850 100644 --- a/14_functions/15_passing-by-value/06_REFERENCE-TYPE/main.go +++ b/14_functions/15_passing-by-value/06_REFERENCE-TYPE/main.go @@ -12,4 +12,4 @@ func main() { func changeMe(z []string) { z[0] = "Todd" fmt.Println(z) // [Todd] -} \ No newline at end of file +} 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 01ae4494..884e2ab5 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 @@ -4,7 +4,7 @@ import "fmt" type Customer struct { name string - age int + age int } func main() { @@ -13,15 +13,15 @@ func main() { changeMe(&c1) - fmt.Println(c1) // {Rocky 44} + fmt.Println(c1) // {Rocky 44} fmt.Println(&c1.name) // 0x8201e4120 } func changeMe(z *Customer) { - fmt.Println(z) // &{Todd 44} + fmt.Println(z) // &{Todd 44} fmt.Println(&z.name) // 0x8201e4120 z.name = "Rocky" - fmt.Println(z) // &{Rocky 44} + fmt.Println(z) // &{Rocky 44} fmt.Println(&z.name) // 0x8201e4120 } diff --git a/14_functions/16_anon_self-executing/main.go b/14_functions/16_anon_self-executing/main.go index 86dc9e69..d3a193a6 100644 --- a/14_functions/16_anon_self-executing/main.go +++ b/14_functions/16_anon_self-executing/main.go @@ -7,5 +7,3 @@ func main() { fmt.Println("I'm driving!") }() } - - diff --git a/15_exercise-solutions/12_exercise_half-bool/01/halfme.go b/15_exercise-solutions/12_exercise_half-bool/01/halfme.go index 0a5e3c79..3a28c8fa 100644 --- a/15_exercise-solutions/12_exercise_half-bool/01/halfme.go +++ b/15_exercise-solutions/12_exercise_half-bool/01/halfme.go @@ -3,7 +3,7 @@ package main import "fmt" func half(n int) (int, bool) { - return n/2, n%2 == 0 + return n / 2, n%2 == 0 } func main() { diff --git a/15_exercise-solutions/12_exercise_half-bool/02/halfme.go b/15_exercise-solutions/12_exercise_half-bool/02/halfme.go index 33e8b7c9..260b23a2 100644 --- a/15_exercise-solutions/12_exercise_half-bool/02/halfme.go +++ b/15_exercise-solutions/12_exercise_half-bool/02/halfme.go @@ -3,7 +3,7 @@ package main import "fmt" func half(n int) (float64, bool) { - return float64(n)/2, n%2 == 0 + return float64(n) / 2, n%2 == 0 } func main() { diff --git a/15_exercise-solutions/13_exercise_variadic/max.go b/15_exercise-solutions/13_exercise_variadic/max.go index ed4d1479..fd04fde3 100644 --- a/15_exercise-solutions/13_exercise_variadic/max.go +++ b/15_exercise-solutions/13_exercise_variadic/max.go @@ -1,4 +1,5 @@ package main + import "fmt" func max(numbers ...int) int { @@ -12,6 +13,6 @@ func max(numbers ...int) int { } func main() { - greatest := max(4,7,9,123,543,23,435,53,125) + greatest := max(4, 7, 9, 123, 543, 23, 435, 53, 125) fmt.Println(greatest) } diff --git a/15_exercise-solutions/18_func-expression/adder.go b/15_exercise-solutions/18_func-expression/adder.go index 693aff39..494e90d9 100644 --- a/15_exercise-solutions/18_func-expression/adder.go +++ b/15_exercise-solutions/18_func-expression/adder.go @@ -7,4 +7,4 @@ func main() { return x + y } fmt.Println(add(1, 4)) -} \ No newline at end of file +} diff --git a/15_exercise-solutions/25_exercises/02_fibonacci/main.go b/15_exercise-solutions/25_exercises/02_fibonacci/main.go index f4a34a4f..c92498dc 100644 --- a/15_exercise-solutions/25_exercises/02_fibonacci/main.go +++ b/15_exercise-solutions/25_exercises/02_fibonacci/main.go @@ -14,6 +14,6 @@ func fibo(xs int) int { return 0 fmt.Println("xs == 0, return 0") } - fmt.Println(xs,"...so...", xs-1, xs-2) + fmt.Println(xs, "...so...", xs-1, xs-2) return fibo(xs-1) + fibo(xs-2) -} \ No newline at end of file +} diff --git a/15_exercise-solutions/aa01_variadic-params/main.go b/15_exercise-solutions/aa01_variadic-params/main.go index 5ef46a4b..34fbda40 100644 --- a/15_exercise-solutions/aa01_variadic-params/main.go +++ b/15_exercise-solutions/aa01_variadic-params/main.go @@ -11,4 +11,4 @@ func Greeting(prefix string, who ...string) { for _, value := range who { fmt.Println(value) } -} \ No newline at end of file +} diff --git a/15_exercise-solutions/aa02_variadic-args/main.go b/15_exercise-solutions/aa02_variadic-args/main.go index 2f2aa228..6e1560c7 100644 --- a/15_exercise-solutions/aa02_variadic-args/main.go +++ b/15_exercise-solutions/aa02_variadic-args/main.go @@ -12,4 +12,4 @@ func Greeting(prefix string, who ...string) { for _, value := range who { fmt.Println(value) } -} \ No newline at end of file +} diff --git a/15_exercise-solutions/aa03_slice-instead-of-variadic/main.go b/15_exercise-solutions/aa03_slice-instead-of-variadic/main.go index 90828427..601c71aa 100644 --- a/15_exercise-solutions/aa03_slice-instead-of-variadic/main.go +++ b/15_exercise-solutions/aa03_slice-instead-of-variadic/main.go @@ -12,4 +12,4 @@ func Greeting(prefix string, who []string) { for _, value := range who { fmt.Println(value) } -} \ No newline at end of file +} diff --git a/15_exercise-solutions/aa04_params-and-args/main.go b/15_exercise-solutions/aa04_params-and-args/main.go index 33d73d4a..80d072e7 100644 --- a/15_exercise-solutions/aa04_params-and-args/main.go +++ b/15_exercise-solutions/aa04_params-and-args/main.go @@ -12,4 +12,4 @@ func main() { func f(numbers ...int) { fmt.Println(numbers) -} \ No newline at end of file +} diff --git a/16_array/01/main.go b/16_array/01/main.go index afe4d4bf..6f70595a 100644 --- a/16_array/01/main.go +++ b/16_array/01/main.go @@ -1,4 +1,5 @@ package main + import "fmt" func main() { diff --git a/16_array/02/main.go b/16_array/02/main.go index 27d27d82..bbee45c2 100644 --- a/16_array/02/main.go +++ b/16_array/02/main.go @@ -1,4 +1,5 @@ package main + import "fmt" func main() { diff --git a/17_slice/01_int-slice/main.go b/17_slice/01_int-slice/main.go index 127423ef..a269efb3 100644 --- a/17_slice/01_int-slice/main.go +++ b/17_slice/01_int-slice/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { - mySlice := []int{1, 3, 5, 7, 9, 11,} + mySlice := []int{1, 3, 5, 7, 9, 11} fmt.Printf("%T\n", mySlice) for i, value := range mySlice { @@ -56,4 +56,4 @@ func main() { fmt.Println(len(mySlice)) fmt.Println(cap(mySlice)) -} \ No newline at end of file +} diff --git a/17_slice/03_slicing-a-slice/02/main.go b/17_slice/03_slicing-a-slice/02/main.go index 6ac749ea..23c9582c 100644 --- a/17_slice/03_slicing-a-slice/02/main.go +++ b/17_slice/03_slicing-a-slice/02/main.go @@ -7,9 +7,9 @@ func main() { var results []int fmt.Println(results) - mySlice := []string{"a", "b", "c", "g", "m", "z",} + 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 -} \ No newline at end of file + 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/17_slice/03_slicing-a-slice/03/main.go b/17_slice/03_slicing-a-slice/03/main.go index fce8cab3..eec50ea8 100644 --- a/17_slice/03_slicing-a-slice/03/main.go +++ b/17_slice/03_slicing-a-slice/03/main.go @@ -22,4 +22,4 @@ func main() { fmt.Println(greeting[5:]) fmt.Print("[:] ") fmt.Println(greeting[:]) -} \ No newline at end of file +} diff --git a/19_struct/11_struct_unmarshal/main.go b/19_struct/11_struct_unmarshal/main.go index 3b8f412b..5f913126 100644 --- a/19_struct/11_struct_unmarshal/main.go +++ b/19_struct/11_struct_unmarshal/main.go @@ -1,16 +1,17 @@ package main + import ( - "fmt" "encoding/json" + "fmt" ) type Data struct { - Email string + Email string Loggedin string Pictures []string } -func main(){ +func main() { var m Data fmt.Println(m) fmt.Println(m.Email) diff --git a/20_playing-with-type/00_types/01_division/01_int-int/main.go b/20_playing-with-type/00_types/01_division/01_int-int/main.go index 35de5c79..2aa53895 100644 --- a/20_playing-with-type/00_types/01_division/01_int-int/main.go +++ b/20_playing-with-type/00_types/01_division/01_int-int/main.go @@ -3,5 +3,5 @@ package main import "fmt" func main() { - fmt.Println(32/16) + fmt.Println(32 / 16) } diff --git a/20_playing-with-type/00_types/01_division/02_int-float/main.go b/20_playing-with-type/00_types/01_division/02_int-float/main.go index 1077eac0..60fa6939 100644 --- a/20_playing-with-type/00_types/01_division/02_int-float/main.go +++ b/20_playing-with-type/00_types/01_division/02_int-float/main.go @@ -3,5 +3,5 @@ package main import "fmt" func main() { - fmt.Println(32/3.74) + fmt.Println(32 / 3.74) } diff --git a/20_playing-with-type/00_types/01_division/03_var_int-float/main.go b/20_playing-with-type/00_types/01_division/03_var_int-float/main.go index 1ff19768..bac33d04 100644 --- a/20_playing-with-type/00_types/01_division/03_var_int-float/main.go +++ b/20_playing-with-type/00_types/01_division/03_var_int-float/main.go @@ -3,6 +3,6 @@ package main import "fmt" func main() { - answer := 32/3.74 + answer := 32 / 3.74 fmt.Println(answer) } diff --git a/20_playing-with-type/00_types/01_division/04_var_int-float_invalid-code/main.go b/20_playing-with-type/00_types/01_division/04_var_int-float_invalid-code/main.go index 9eff0c8a..1fe542e6 100644 --- a/20_playing-with-type/00_types/01_division/04_var_int-float_invalid-code/main.go +++ b/20_playing-with-type/00_types/01_division/04_var_int-float_invalid-code/main.go @@ -4,6 +4,6 @@ import "fmt" func main() { var answer int - answer = 32/3.74 + answer = 32 / 3.74 fmt.Println(answer) } diff --git a/20_playing-with-type/00_types/02_strings/02_sequence-of-bytes/main.go b/20_playing-with-type/00_types/02_strings/02_sequence-of-bytes/main.go index 10183314..7b5a68f0 100644 --- a/20_playing-with-type/00_types/02_strings/02_sequence-of-bytes/main.go +++ b/20_playing-with-type/00_types/02_strings/02_sequence-of-bytes/main.go @@ -1,4 +1,5 @@ package main + import "fmt" func main() { diff --git a/20_playing-with-type/00_types/02_strings/03_immutable/main.go b/20_playing-with-type/00_types/02_strings/03_immutable/main.go index f4b67403..5ad4c22f 100644 --- a/20_playing-with-type/00_types/02_strings/03_immutable/main.go +++ b/20_playing-with-type/00_types/02_strings/03_immutable/main.go @@ -1,4 +1,5 @@ package main + import "fmt" func main() { @@ -8,8 +9,8 @@ func main() { intro = "Hahahaha!" fmt.Println(intro) fmt.Println(&intro) -// the below is invalid -// intro[0] = 70 -// fmt.Println(intro) -// fmt.Println(&intro) + // the below is invalid + // intro[0] = 70 + // fmt.Println(intro) + // fmt.Println(&intro) } diff --git a/20_playing-with-type/00_types/03_strconv/01_itoa/main.go b/20_playing-with-type/00_types/03_strconv/01_itoa/main.go index 8a05b7f5..263d0801 100644 --- a/20_playing-with-type/00_types/03_strconv/01_itoa/main.go +++ b/20_playing-with-type/00_types/03_strconv/01_itoa/main.go @@ -1,7 +1,8 @@ package main + import ( - "strconv" "fmt" + "strconv" ) func main() { diff --git a/20_playing-with-type/00_types/03_strconv/03_atoi/main.go b/20_playing-with-type/00_types/03_strconv/03_atoi/main.go index 55c4489c..350dfa01 100644 --- a/20_playing-with-type/00_types/03_strconv/03_atoi/main.go +++ b/20_playing-with-type/00_types/03_strconv/03_atoi/main.go @@ -7,5 +7,5 @@ import ( func main() { i, _ := strconv.Atoi("32") - fmt.Println(i+10) + fmt.Println(i + 10) } diff --git a/20_playing-with-type/00_types/06_math-pkg/main.go b/20_playing-with-type/00_types/06_math-pkg/main.go index 44b07d52..ebc61f01 100644 --- a/20_playing-with-type/00_types/06_math-pkg/main.go +++ b/20_playing-with-type/00_types/06_math-pkg/main.go @@ -1,4 +1,5 @@ package main + import ( "fmt" "math" diff --git a/20_playing-with-type/00_types/07_typeOf/01_better-code/main.go b/20_playing-with-type/00_types/07_typeOf/01_better-code/main.go index b3302e0f..b9beac2d 100644 --- a/20_playing-with-type/00_types/07_typeOf/01_better-code/main.go +++ b/20_playing-with-type/00_types/07_typeOf/01_better-code/main.go @@ -9,8 +9,8 @@ func main() { a := "this is stored in the variable a" b := 42 c, d, e, f := 44.7, true, false, 'm' // single quotes - g := "g" // double quotes - h := `h` // back ticks + g := "g" // double quotes + h := `h` // back ticks fmt.Println("a - ", reflect.TypeOf(a), " - ", a) fmt.Println("b - ", reflect.TypeOf(b), " - ", b) @@ -21,4 +21,4 @@ func main() { fmt.Println("g - ", reflect.TypeOf(g), " - ", g) fmt.Println("h - ", reflect.TypeOf(h), " - ", h) fmt.Printf("h - %T\n", h) -} \ No newline at end of file +} diff --git a/20_playing-with-type/00_types/07_typeOf/02_worse-code/main.go b/20_playing-with-type/00_types/07_typeOf/02_worse-code/main.go index 2e6fbadb..20d1a16b 100644 --- a/20_playing-with-type/00_types/07_typeOf/02_worse-code/main.go +++ b/20_playing-with-type/00_types/07_typeOf/02_worse-code/main.go @@ -6,19 +6,19 @@ import ( ) var a string = "this is stored in the variable a" // package scope -var b, c string = "stored in b", "stored in c" // package scope -var d string // package scope +var b, c string = "stored in b", "stored in c" // package scope +var d string // package scope func main() { d = "stored in d" // declaration above; assignment here; package scope - var e int = 42 // function scope - subsequent variables have same package scope: + var e int = 42 // function scope - subsequent variables have same package scope: f := 43 g := "stored in g" h, i := "stored in h", "stored in i" j, k, l, m := 44.7, true, false, 'm' // single quotes - n := "n" // double quotes - o := `o` // back ticks + n := "n" // double quotes + o := `o` // back ticks fmt.Println("a - ", reflect.TypeOf(a), " - ", a) fmt.Println("b - ", reflect.TypeOf(b), " - ", b) @@ -36,4 +36,4 @@ func main() { fmt.Println("n - ", reflect.TypeOf(n), " - ", n) fmt.Println("o - ", reflect.TypeOf(o), " - ", o) fmt.Printf("o - %T\n", o) -} \ No newline at end of file +} diff --git a/20_playing-with-type/01_struct/main.go b/20_playing-with-type/01_struct/main.go index 8d7f65ba..0c53fc4b 100644 --- a/20_playing-with-type/01_struct/main.go +++ b/20_playing-with-type/01_struct/main.go @@ -12,7 +12,7 @@ func main() { fmt.Println(p1) fmt.Println(p1.name) fmt.Println(p1.age) - fmt.Printf("%T\n",p1) + fmt.Printf("%T\n", p1) } -// we've already seen the above code \ No newline at end of file +// we've already seen the above code diff --git a/20_playing-with-type/02_string/main.go b/20_playing-with-type/02_string/main.go index 2759e9f4..b61a2042 100644 --- a/20_playing-with-type/02_string/main.go +++ b/20_playing-with-type/02_string/main.go @@ -8,4 +8,4 @@ func main() { var message mySentence = "Hello World!" fmt.Println(message) fmt.Printf("%T\n", message) -} \ No newline at end of file +} diff --git a/20_playing-with-type/03_string-conversion/main.go b/20_playing-with-type/03_string-conversion/main.go index eaba3572..eb89ccc1 100644 --- a/20_playing-with-type/03_string-conversion/main.go +++ b/20_playing-with-type/03_string-conversion/main.go @@ -9,4 +9,4 @@ func main() { fmt.Println(message) fmt.Printf("%T\n", message) fmt.Printf("%T\n", string(message)) -} \ No newline at end of file +} diff --git a/20_playing-with-type/04_string_assertion_invalid-code/main.go b/20_playing-with-type/04_string_assertion_invalid-code/main.go index 109b05d9..fd244cb4 100644 --- a/20_playing-with-type/04_string_assertion_invalid-code/main.go +++ b/20_playing-with-type/04_string_assertion_invalid-code/main.go @@ -9,4 +9,4 @@ func main() { fmt.Println(message) fmt.Printf("%T\n", message) fmt.Printf("%T\n", message.(string)) -} \ No newline at end of file +} diff --git a/20_playing-with-type/05_var-for-zero-val-initalization/main.go b/20_playing-with-type/05_var-for-zero-val-initalization/main.go index 18d02b00..a03cb0aa 100644 --- a/20_playing-with-type/05_var-for-zero-val-initalization/main.go +++ b/20_playing-with-type/05_var-for-zero-val-initalization/main.go @@ -12,8 +12,8 @@ func main() { fmt.Println(p1) fmt.Println(p1.name) fmt.Println(p1.age) - fmt.Printf("%T\n",p1) + fmt.Printf("%T\n", p1) } // always use var to create and -// initialize a variable to its zero value \ No newline at end of file +// initialize a variable to its zero value diff --git a/20_playing-with-type/xx05_slice-strings/main.go b/20_playing-with-type/xx05_slice-strings/main.go index fa049be7..98812515 100644 --- a/20_playing-with-type/xx05_slice-strings/main.go +++ b/20_playing-with-type/xx05_slice-strings/main.go @@ -5,7 +5,7 @@ import "fmt" type mySentences []string func main() { - var messages mySentences = []string{"Hello World!", "More coffee",} + var messages mySentences = []string{"Hello World!", "More coffee"} fmt.Println(messages) fmt.Printf("%T\n", messages) -} \ No newline at end of file +} diff --git a/20_playing-with-type/xx06_slice-strings_conversion/main.go b/20_playing-with-type/xx06_slice-strings_conversion/main.go index 8309d38f..aadd32ef 100644 --- a/20_playing-with-type/xx06_slice-strings_conversion/main.go +++ b/20_playing-with-type/xx06_slice-strings_conversion/main.go @@ -5,8 +5,8 @@ import "fmt" type mySentences []string func main() { - var messages mySentences = []string{"Hello World!", "More coffee",} + var messages mySentences = []string{"Hello World!", "More coffee"} fmt.Println(messages) fmt.Printf("%T\n", messages) fmt.Printf("%T\n", []string(messages)) -} \ No newline at end of file +} diff --git a/20_playing-with-type/xx07_int/main.go b/20_playing-with-type/xx07_int/main.go index 22049d11..2bb66bcd 100644 --- a/20_playing-with-type/xx07_int/main.go +++ b/20_playing-with-type/xx07_int/main.go @@ -9,4 +9,4 @@ func main() { fmt.Println(x) fmt.Printf("%T\n", x) fmt.Printf("%T\n", int(x)) -} \ No newline at end of file +} diff --git a/20_playing-with-type/xx08_slice-ints/main.go b/20_playing-with-type/xx08_slice-ints/main.go index eaa55601..2d49e40d 100644 --- a/20_playing-with-type/xx08_slice-ints/main.go +++ b/20_playing-with-type/xx08_slice-ints/main.go @@ -5,8 +5,8 @@ import "fmt" type myType []int func main() { - var x myType = []int{32,44,57,} + var x myType = []int{32, 44, 57} fmt.Println(x) fmt.Printf("%T\n", x) fmt.Printf("%T\n", []int(x)) -} \ No newline at end of file +} diff --git a/23_methods/02_struct_value-receiver/02/main.go b/23_methods/02_struct_value-receiver/02/main.go index 94902625..9cf5384d 100644 --- a/23_methods/02_struct_value-receiver/02/main.go +++ b/23_methods/02_struct_value-receiver/02/main.go @@ -18,5 +18,6 @@ func main() { fmt.Println(p1.fullName()) fmt.Printf("Inside main: %p\n", &p1) } + // p1 is the receiver value for the call to fullName -// fullName is operating on a copy of p1 \ No newline at end of file +// fullName is operating on a copy of p1 diff --git a/23_methods/03_struct_pointer-receiver/02/main.go b/23_methods/03_struct_pointer-receiver/02/main.go index ea309754..6a521948 100644 --- a/23_methods/03_struct_pointer-receiver/02/main.go +++ b/23_methods/03_struct_pointer-receiver/02/main.go @@ -18,4 +18,5 @@ func main() { p1.changeAge(21) fmt.Printf("Inside main: %p\n", &p1) } -// passes the reference; the memory address \ No newline at end of file + +// passes the reference; the memory address diff --git a/25_interfaces/01_vehicle-example/02_empty-interface/main.go b/25_interfaces/01_vehicle-example/02_empty-interface/main.go index 7bdc085a..e68873a8 100644 --- a/25_interfaces/01_vehicle-example/02_empty-interface/main.go +++ b/25_interfaces/01_vehicle-example/02_empty-interface/main.go @@ -40,7 +40,7 @@ func main() { sanger := Boat{} nautique := Boat{} malibu := Boat{} - rides := []Vehicles{prius, tacoma, bmw528, boeing747, boeing757, boeing767,sanger, nautique, malibu,} + rides := []Vehicles{prius, tacoma, bmw528, boeing747, boeing757, boeing767, sanger, nautique, malibu} for key, value := range rides { fmt.Println(key, " - ", value) diff --git a/25_interfaces/02_shape-example/01_no-interface/main.go b/25_interfaces/02_shape-example/01_no-interface/main.go index 887f756a..333642a2 100644 --- a/25_interfaces/02_shape-example/01_no-interface/main.go +++ b/25_interfaces/02_shape-example/01_no-interface/main.go @@ -27,5 +27,6 @@ func main() { totalArea := c.area() + s.area() fmt.Println("Total Area: ", totalArea) } + // what if I had thousands of shapes? -// how would I create a function to sum their areas? \ No newline at end of file +// how would I create a function to sum their areas? diff --git a/25_interfaces/02_shape-example/02_interface/main.go b/25_interfaces/02_shape-example/02_interface/main.go index 466735de..e962654e 100644 --- a/25_interfaces/02_shape-example/02_interface/main.go +++ b/25_interfaces/02_shape-example/02_interface/main.go @@ -37,4 +37,4 @@ func main() { c := Circle{5} s := Square{10} fmt.Println("Total Area: ", totalArea(c, s)) -} \ No newline at end of file +} diff --git a/25_interfaces/02_shape-example/03_interface/main.go b/25_interfaces/02_shape-example/03_interface/main.go index a9bad9c9..c4fea467 100644 --- a/25_interfaces/02_shape-example/03_interface/main.go +++ b/25_interfaces/02_shape-example/03_interface/main.go @@ -35,4 +35,4 @@ func main() { sqr := Square{10} measure(circ) measure(sqr) -} \ No newline at end of file +} diff --git a/25_interfaces/03_empty-interface/02_slice-of-any-type/main.go b/25_interfaces/03_empty-interface/02_slice-of-any-type/main.go index 8e53c30c..1d075c1d 100644 --- a/25_interfaces/03_empty-interface/02_slice-of-any-type/main.go +++ b/25_interfaces/03_empty-interface/02_slice-of-any-type/main.go @@ -16,11 +16,10 @@ type Cat struct { annoying bool } - func main() { fido := Dog{Animal{"woof"}, true} fifi := Cat{Animal{"meow"}, true} shadow := Dog{Animal{"woof"}, true} - critters := []interface{}{fido, fifi, shadow,} + critters := []interface{}{fido, fifi, shadow} fmt.Println(critters) } diff --git a/26_package-os/00_args/main.go b/26_package-os/00_args/main.go index f26504f2..66dae938 100644 --- a/26_package-os/00_args/main.go +++ b/26_package-os/00_args/main.go @@ -17,4 +17,4 @@ go install step 2 - from terminal: programName arguments -*/ \ No newline at end of file +*/ diff --git a/26_package-os/01_Read/01/main.go b/26_package-os/01_Read/01/main.go index d27c1521..9e0804b8 100644 --- a/26_package-os/01_Read/01/main.go +++ b/26_package-os/01_Read/01/main.go @@ -24,4 +24,4 @@ func main() { // this is a limit reader // we limit what is read -// see io.ReadFull for func similiar to (*File)Read \ No newline at end of file +// see io.ReadFull for func similiar to (*File)Read diff --git a/26_package-os/02_Write/01/main.go b/26_package-os/02_Write/01/main.go index d4e4f799..08af5383 100644 --- a/26_package-os/02_Write/01/main.go +++ b/26_package-os/02_Write/01/main.go @@ -1,8 +1,8 @@ package main import ( - "os" "log" + "os" ) func main() { @@ -37,4 +37,4 @@ go install step 2 - at command line enter: programName initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/26_package-os/02_Write/02/main.go b/26_package-os/02_Write/02/main.go index ae932d5f..49f37386 100644 --- a/26_package-os/02_Write/02/main.go +++ b/26_package-os/02_Write/02/main.go @@ -19,4 +19,4 @@ func main() { if err != nil { log.Fatalln("error writing to file: ", err.Error()) } -} \ No newline at end of file +} diff --git a/26_package-os/02_Write/03_absolute-path/main.go b/26_package-os/02_Write/03_absolute-path/main.go index 49df7ce7..84ee0bd3 100644 --- a/26_package-os/02_Write/03_absolute-path/main.go +++ b/26_package-os/02_Write/03_absolute-path/main.go @@ -19,4 +19,4 @@ func main() { if err != nil { log.Fatalln("error writing to file: ", err.Error()) } -} \ No newline at end of file +} diff --git a/26_package-os/03_mkdir/01/main.go b/26_package-os/03_mkdir/01/main.go index e3180e7b..809ce032 100644 --- a/26_package-os/03_mkdir/01/main.go +++ b/26_package-os/03_mkdir/01/main.go @@ -26,6 +26,7 @@ func main() { log.Fatalln("error writing to file: ", err.Error()) } } + /* step 1 - at command line enter: @@ -47,4 +48,4 @@ ls /somefolderthatdoesntexist use at command line to remove folder: rm -rf /somefolderthatdoesntexist -*/ \ No newline at end of file +*/ diff --git a/26_package-os/03_mkdir/02/main.go b/26_package-os/03_mkdir/02/main.go index 7c6f1e30..92c4f86d 100644 --- a/26_package-os/03_mkdir/02/main.go +++ b/26_package-os/03_mkdir/02/main.go @@ -27,6 +27,7 @@ func main() { log.Fatalln("error writing to file: ", err.Error()) } } + /* step 1 - at command line enter: @@ -48,4 +49,4 @@ ls /somefolderthatdoesntexist use at command line to remove folder: rm -rf /somefolderthatdoesntexist -*/ \ No newline at end of file +*/ diff --git a/26_package-os/04_FileMode/01/main.go b/26_package-os/04_FileMode/01/main.go index 11c9c799..9f8904de 100644 --- a/26_package-os/04_FileMode/01/main.go +++ b/26_package-os/04_FileMode/01/main.go @@ -1,4 +1,5 @@ package main + import ( "fmt" "os" diff --git a/26_package-os/05_file-open/main.go b/26_package-os/05_file-open/main.go index 4e3e8edd..8d41fb93 100644 --- a/26_package-os/05_file-open/main.go +++ b/26_package-os/05_file-open/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" + "os" ) func main() { @@ -31,4 +31,4 @@ go install step 2 - at command line enter: 06_cat main.go -*/ \ No newline at end of file +*/ diff --git a/26_package-os/06_file-create/main.go b/26_package-os/06_file-create/main.go index 93832053..8911038f 100644 --- a/26_package-os/06_file-create/main.go +++ b/26_package-os/06_file-create/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io/ioutil" + "log" + "os" ) func main() { @@ -37,4 +37,4 @@ go install step 2 - at command line enter: 07_copy main.go -*/ \ No newline at end of file +*/ diff --git a/26_package-os/07_Stdout_Stdin/02/main.go b/26_package-os/07_Stdout_Stdin/02/main.go index f8f2831f..2d123e41 100644 --- a/26_package-os/07_Stdout_Stdin/02/main.go +++ b/26_package-os/07_Stdout_Stdin/02/main.go @@ -1,9 +1,9 @@ package main import ( - "strings" "io" "os" + "strings" ) func main() { diff --git a/27_package-strings/01_strings/main.go b/27_package-strings/01_strings/main.go index 8924709d..c5dccd4f 100644 --- a/27_package-strings/01_strings/main.go +++ b/27_package-strings/01_strings/main.go @@ -23,7 +23,7 @@ func main() { strings.Index("test", "e"), // "a-b" - strings.Join([]string{"a","b"}, "-"), + strings.Join([]string{"a", "b"}, "-"), // == "aaaaa" strings.Repeat("a", 5), @@ -47,6 +47,6 @@ func main() { arr := []byte("test") fmt.Println(arr) - str := string([]byte{'t','e','s','t'}) + str := string([]byte{'t', 'e', 's', 't'}) fmt.Println(str) -} \ No newline at end of file +} diff --git a/27_package-strings/02_NewReader/main.go b/27_package-strings/02_NewReader/main.go index 3384ca2c..4001f153 100644 --- a/27_package-strings/02_NewReader/main.go +++ b/27_package-strings/02_NewReader/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io" + "log" + "os" "strings" ) @@ -19,6 +19,7 @@ func main() { io.Copy(dst, rdr) } + /* io.Copy @@ -32,7 +33,6 @@ func (r *Reader) Read(b []byte) (n int, err error) */ - /* step 1 - at command line enter: diff --git a/28_package-bufio/01_NewReader/main.go b/28_package-bufio/01_NewReader/main.go index ac04ad70..725ae42f 100644 --- a/28_package-bufio/01_NewReader/main.go +++ b/28_package-bufio/01_NewReader/main.go @@ -1,11 +1,11 @@ package main import ( - "os" - "log" + "bufio" "fmt" "io" - "bufio" + "log" + "os" ) func cp(srcName, dstName string) error { @@ -56,4 +56,4 @@ go install step 2 - at command line enter: programName initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/28_package-bufio/02_NewScanner/main.go b/28_package-bufio/02_NewScanner/main.go index 2d73c81d..6cf57e17 100644 --- a/28_package-bufio/02_NewScanner/main.go +++ b/28_package-bufio/02_NewScanner/main.go @@ -1,9 +1,10 @@ package main + import ( - "fmt" - "os" "bufio" + "fmt" "log" + "os" ) func main() { @@ -19,6 +20,7 @@ func main() { fmt.Println(">>>", line) } } + /* scanners allow us to interact with files line-by-line */ diff --git a/28_package-bufio/03_scan-lines/02/main.go b/28_package-bufio/03_scan-lines/02/main.go index f4cb637a..48795918 100644 --- a/28_package-bufio/03_scan-lines/02/main.go +++ b/28_package-bufio/03_scan-lines/02/main.go @@ -1,8 +1,9 @@ package main + import ( - "os" - "fmt" "bufio" + "fmt" + "os" ) func main() { diff --git a/28_package-bufio/04_scan-words/02/main.go b/28_package-bufio/04_scan-words/02/main.go index 67693104..a165b593 100644 --- a/28_package-bufio/04_scan-words/02/main.go +++ b/28_package-bufio/04_scan-words/02/main.go @@ -1,8 +1,9 @@ package main + import ( - "os" - "fmt" "bufio" + "fmt" + "os" "strings" ) diff --git a/28_package-bufio/04_scan-words/03/main.go b/28_package-bufio/04_scan-words/03/main.go index e8a0ab30..8875c1f4 100644 --- a/28_package-bufio/04_scan-words/03/main.go +++ b/28_package-bufio/04_scan-words/03/main.go @@ -1,8 +1,9 @@ package main + import ( - "os" - "fmt" "bufio" + "fmt" + "os" "strings" ) diff --git a/29_package-io/01_copy/main.go b/29_package-io/01_copy/main.go index f8f2831f..2d123e41 100644 --- a/29_package-io/01_copy/main.go +++ b/29_package-io/01_copy/main.go @@ -1,9 +1,9 @@ package main import ( - "strings" "io" "os" + "strings" ) func main() { diff --git a/29_package-io/02_copy/main.go b/29_package-io/02_copy/main.go index 8b1d3c31..415ceea1 100644 --- a/29_package-io/02_copy/main.go +++ b/29_package-io/02_copy/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" "fmt" "io" + "log" + "os" ) func cp(srcName, dstName string) error { @@ -53,4 +53,4 @@ go install step 2 - at command line enter: 04_io-copy initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/29_package-io/03_copy/main.go b/29_package-io/03_copy/main.go index 3384ca2c..4001f153 100644 --- a/29_package-io/03_copy/main.go +++ b/29_package-io/03_copy/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io" + "log" + "os" "strings" ) @@ -19,6 +19,7 @@ func main() { io.Copy(dst, rdr) } + /* io.Copy @@ -32,7 +33,6 @@ func (r *Reader) Read(b []byte) (n int, err error) */ - /* step 1 - at command line enter: diff --git a/29_package-io/04_TeeReader/02/main.go b/29_package-io/04_TeeReader/02/main.go index cc888fd6..42b59e64 100644 --- a/29_package-io/04_TeeReader/02/main.go +++ b/29_package-io/04_TeeReader/02/main.go @@ -45,4 +45,4 @@ func TeeReader(r Reader, w Writer) Reader TeeReader returns a Reader that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error. - */ \ No newline at end of file +*/ diff --git a/29_package-io/05_ReadFull/main.go b/29_package-io/05_ReadFull/main.go index 7427a489..e2d45d02 100644 --- a/29_package-io/05_ReadFull/main.go +++ b/29_package-io/05_ReadFull/main.go @@ -1,8 +1,8 @@ package main import ( - "os" "io" + "os" ) func main() { @@ -26,4 +26,4 @@ func main() { // this is a limit reader // we limit what is read -// see (*File)Read (os package) for func similiar to io.ReadFull \ No newline at end of file +// see (*File)Read (os package) for func similiar to io.ReadFull diff --git a/29_package-io/06_LimitReader/main.go b/29_package-io/06_LimitReader/main.go index a5abf14c..7625d554 100644 --- a/29_package-io/06_LimitReader/main.go +++ b/29_package-io/06_LimitReader/main.go @@ -1,8 +1,8 @@ package main import ( - "os" "io" + "os" ) func main() { @@ -21,4 +21,4 @@ func main() { rdr := io.LimitReader(src, 5) io.Copy(dst, rdr) -} \ No newline at end of file +} diff --git a/29_package-io/07_WriteString/01_one-way/main.go b/29_package-io/07_WriteString/01_one-way/main.go index 94a136e6..279cd293 100644 --- a/29_package-io/07_WriteString/01_one-way/main.go +++ b/29_package-io/07_WriteString/01_one-way/main.go @@ -16,7 +16,7 @@ func main() { str := "Put some phrase here." bs := []byte(str) - _, err = f.Write(bs) + _, err = f.Write(bs) if err != nil { log.Fatalln("error writing to file: ", err.Error()) } @@ -29,4 +29,4 @@ func WriteString(w Writer, s string) (n int, err error) WriteString writes the contents of the string s to w, which accepts a slice of bytes. If w implements a WriteString method, it is invoked directly. -*/ \ No newline at end of file +*/ diff --git a/29_package-io/07_WriteString/02_another-way/main.go b/29_package-io/07_WriteString/02_another-way/main.go index 246f2749..bb84f371 100644 --- a/29_package-io/07_WriteString/02_another-way/main.go +++ b/29_package-io/07_WriteString/02_another-way/main.go @@ -1,9 +1,9 @@ package main import ( + "io" "log" "os" - "io" ) func main() { @@ -15,7 +15,7 @@ func main() { defer f.Close() str := "Put some phrase here." -// bs := []byte(str) + // bs := []byte(str) _, err = io.WriteString(f, str) // _, err = f.Write(bs) @@ -31,4 +31,4 @@ func WriteString(w Writer, s string) (n int, err error) WriteString writes the contents of the string s to w, which accepts a slice of bytes. If w implements a WriteString method, it is invoked directly. -*/ \ No newline at end of file +*/ diff --git a/30_package-ioutil/00_ReadAll/main.go b/30_package-ioutil/00_ReadAll/main.go index e1d5db9b..e3154417 100644 --- a/30_package-ioutil/00_ReadAll/main.go +++ b/30_package-ioutil/00_ReadAll/main.go @@ -1,9 +1,9 @@ package main import ( - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" "strings" ) @@ -28,4 +28,4 @@ go install step 2 - at command line enter: 06_cat main.go -*/ \ No newline at end of file +*/ diff --git a/30_package-ioutil/01_ReadAll/main.go b/30_package-ioutil/01_ReadAll/main.go index 4e3e8edd..8d41fb93 100644 --- a/30_package-ioutil/01_ReadAll/main.go +++ b/30_package-ioutil/01_ReadAll/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" + "os" ) func main() { @@ -31,4 +31,4 @@ go install step 2 - at command line enter: 06_cat main.go -*/ \ No newline at end of file +*/ diff --git a/31_package-encoding-csv/03_panics/main.go b/31_package-encoding-csv/03_panics/main.go index 9160fc66..9b23d328 100644 --- a/31_package-encoding-csv/03_panics/main.go +++ b/31_package-encoding-csv/03_panics/main.go @@ -39,7 +39,6 @@ func main() { log.Fatalln(err) } - if rowCount == 0 { for idx, column := range record { columns[column] = idx diff --git a/31_package-encoding-csv/04_parse-state/main.go b/31_package-encoding-csv/04_parse-state/main.go index b0c3e3dc..348d1812 100644 --- a/31_package-encoding-csv/04_parse-state/main.go +++ b/31_package-encoding-csv/04_parse-state/main.go @@ -24,9 +24,9 @@ func parseState(columns map[string]int, record []string) (*state, error) { return nil, err } return &state{ - id: id, - name: name, - abbreviation: abbreviation, + id: id, + name: name, + abbreviation: abbreviation, censusRegionName: censusRegionName, }, nil } @@ -52,7 +52,6 @@ func main() { log.Fatalln(err) } - if rowCount == 0 { for idx, column := range record { columns[column] = idx diff --git a/31_package-encoding-csv/05_state-lookup/main.go b/31_package-encoding-csv/05_state-lookup/main.go index 0ff84302..20cc4dbd 100644 --- a/31_package-encoding-csv/05_state-lookup/main.go +++ b/31_package-encoding-csv/05_state-lookup/main.go @@ -81,6 +81,7 @@ func main() { } fmt.Println(state) } + /* at terminal: go install diff --git a/31_package-encoding-csv/06_write-to-html/main.go b/31_package-encoding-csv/06_write-to-html/main.go index 08a09f91..03f66682 100644 --- a/31_package-encoding-csv/06_write-to-html/main.go +++ b/31_package-encoding-csv/06_write-to-html/main.go @@ -102,6 +102,7 @@ func main() { `) } + /* at terminal: go install diff --git a/31_package-encoding-csv/07_NewReader/main.go b/31_package-encoding-csv/07_NewReader/main.go index 103748b4..44b06519 100644 --- a/31_package-encoding-csv/07_NewReader/main.go +++ b/31_package-encoding-csv/07_NewReader/main.go @@ -39,6 +39,3 @@ func main() { } } - - - diff --git a/32_package-path-filepath/01_Walk/main.go b/32_package-path-filepath/01_Walk/main.go index 516ef796..5ca31fde 100644 --- a/32_package-path-filepath/01_Walk/main.go +++ b/32_package-path-filepath/01_Walk/main.go @@ -13,10 +13,7 @@ func main() { }) } - - - /* walk is recursive readdir is not - */ +*/ diff --git a/32_package-path-filepath/02_Walk/main.go b/32_package-path-filepath/02_Walk/main.go index 83cf7a3f..4fb1a7b6 100644 --- a/32_package-path-filepath/02_Walk/main.go +++ b/32_package-path-filepath/02_Walk/main.go @@ -13,10 +13,7 @@ func main() { }) } - - - /* walk is recursive readdir is not - */ +*/ diff --git a/32_package-path-filepath/03_Walk/main.go b/32_package-path-filepath/03_Walk/main.go index 9aa37d81..586fa167 100644 --- a/32_package-path-filepath/03_Walk/main.go +++ b/32_package-path-filepath/03_Walk/main.go @@ -18,10 +18,7 @@ func main() { }) } - - - /* walk is recursive readdir is not - */ +*/ diff --git a/32_package-path-filepath/04_Walk/main.go b/32_package-path-filepath/04_Walk/main.go index c495456c..5eafecdf 100644 --- a/32_package-path-filepath/04_Walk/main.go +++ b/32_package-path-filepath/04_Walk/main.go @@ -32,10 +32,7 @@ func main() { }) } - - - /* walk is recursive readdir is not - */ +*/ diff --git a/33_package-time/04_date-diff/main.go b/33_package-time/04_date-diff/main.go index cdc97a38..a4c79579 100644 --- a/33_package-time/04_date-diff/main.go +++ b/33_package-time/04_date-diff/main.go @@ -16,5 +16,3 @@ func main() { fmt.Println("elapsed days:", int(dur/(time.Hour*24))) } - - diff --git a/34_hash/01_FNV/01/main.go b/34_hash/01_FNV/01/main.go index 30e57c71..8fb583bd 100644 --- a/34_hash/01_FNV/01/main.go +++ b/34_hash/01_FNV/01/main.go @@ -17,4 +17,4 @@ func main() { h := fnv.New64() io.Copy(h, f) fmt.Println(h.Sum64()) -} \ No newline at end of file +} diff --git a/34_hash/01_FNV/02/main.go b/34_hash/01_FNV/02/main.go index bd9499d0..e808d69e 100644 --- a/34_hash/01_FNV/02/main.go +++ b/34_hash/01_FNV/02/main.go @@ -17,4 +17,4 @@ func main() { h := fnv.New64() io.Copy(h, f) fmt.Println("The sum is:", h.Sum64()) -} \ No newline at end of file +} diff --git a/34_hash/02_MD5/01/main.go b/34_hash/02_MD5/01/main.go index df892757..c84ce5cb 100644 --- a/34_hash/02_MD5/01/main.go +++ b/34_hash/02_MD5/01/main.go @@ -1,10 +1,10 @@ package main import ( + "crypto/md5" "fmt" "io" "os" - "crypto/md5" ) func main() { @@ -17,4 +17,4 @@ func main() { h := md5.New() io.Copy(h, f) fmt.Printf("%x\n", h.Sum(nil)) -} \ No newline at end of file +} diff --git a/34_hash/02_MD5/02/main.go b/34_hash/02_MD5/02/main.go index 906d00ec..24844ba5 100644 --- a/34_hash/02_MD5/02/main.go +++ b/34_hash/02_MD5/02/main.go @@ -1,12 +1,12 @@ package main import ( - "fmt" "crypto/md5" - "os" - "log" + "fmt" "io" "io/ioutil" + "log" + "os" ) func main() { @@ -25,10 +25,10 @@ func main() { // or this way // but reads all the bytes at once, then does it - f.Seek(0,0) + f.Seek(0, 0) bs, err := ioutil.ReadAll(f) if err != nil { log.Fatalln("readall didn't read well", err.Error()) } fmt.Printf("The hash (sum) is: %x\n", md5.Sum(bs)) -} \ No newline at end of file +} diff --git a/35_package-filepath/01_walk/main.go b/35_package-filepath/01_walk/main.go index 0255ee9c..2a005f8a 100644 --- a/35_package-filepath/01_walk/main.go +++ b/35_package-filepath/01_walk/main.go @@ -6,7 +6,6 @@ import ( "path/filepath" ) - func walk() { var counter int filepath.Walk(".", func(path string, info os.FileInfo, err error) error { diff --git a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/01/main.go b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/01/main.go index 3878f59c..bac33089 100644 --- a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/01/main.go +++ b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/01/main.go @@ -1,39 +1,38 @@ package main import ( - "net/http" - "io/ioutil" "encoding/xml" "fmt" + "io/ioutil" + "net/http" ) func main() { - + resp, _ := http.Get("http://dev.markitondemand.com/Api/v2/Quote?symbol=googl") defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - + quote := new(QuoteResponse) xml.Unmarshal(body, "e) - + fmt.Printf("%s: %.2f", quote.Name, quote.LastPrice) - -} +} type QuoteResponse struct { - Status string - Name string - LastPrice float32 - Change float32 - ChangePercent float32 - TimeStamp string - MSDate float32 - MarketCap int - Volume int - ChangeYTD float32 + Status string + Name string + LastPrice float32 + Change float32 + ChangePercent float32 + TimeStamp string + MSDate float32 + MarketCap int + Volume int + ChangeYTD float32 ChangePercentYTD float32 - High float32 - Low float32 - Open float32 -} \ No newline at end of file + High float32 + Low float32 + Open float32 +} diff --git a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/02/main.go b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/02/main.go index a4d31e29..5a1f257e 100644 --- a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/02/main.go +++ b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/02/main.go @@ -55,4 +55,4 @@ type QuoteResponse struct { High float32 Low float32 Open float32 -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/03/main.go b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/03/main.go index c8fec9cd..be08026a 100644 --- a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/03/main.go +++ b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/03/main.go @@ -23,18 +23,18 @@ func main() { "tmus", "s", } - + numComplete := 0 for _, symbol := range stockSymbols { - go func(symbol string){ + go func(symbol string) { resp, _ := http.Get("http://dev.markitondemand.com/Api/v2/Quote?symbol=" + symbol) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) - + quote := new(QuoteResponse) xml.Unmarshal(body, "e) - + fmt.Printf("%s: $%.2f\n", quote.Name, quote.LastPrice) numComplete++ }(symbol) @@ -63,4 +63,4 @@ type QuoteResponse struct { High float32 Low float32 Open float32 -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/04/main.go b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/04/main.go index c63c92a3..bd7ddb9c 100644 --- a/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/04/main.go +++ b/36_concurrency/01_concurrency_PS/02_stock-symbol-lookup/04/main.go @@ -5,8 +5,8 @@ import ( "fmt" "io/ioutil" "net/http" - "time" "runtime" + "time" ) func main() { @@ -29,7 +29,7 @@ func main() { numComplete := 0 for _, symbol := range stockSymbols { - go func(symbol string){ + go func(symbol string) { resp, _ := http.Get("http://dev.markitondemand.com/Api/v2/Quote?symbol=" + symbol) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) @@ -65,4 +65,4 @@ type QuoteResponse struct { High float32 Low float32 Open float32 -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/03_file-watcher/main.go b/36_concurrency/01_concurrency_PS/03_file-watcher/main.go index d5b67c03..57e2172c 100644 --- a/36_concurrency/01_concurrency_PS/03_file-watcher/main.go +++ b/36_concurrency/01_concurrency_PS/03_file-watcher/main.go @@ -1,13 +1,13 @@ package main import ( + "encoding/csv" "fmt" - "os" - "time" "io/ioutil" - "strings" - "encoding/csv" + "os" "strconv" + "strings" + "time" ) const watchedPath = "./source" @@ -43,8 +43,8 @@ func main() { } type Invoice struct { - Number string - Amount float64 + Number string + Amount float64 PurchaseOrderNumber int - InvoiceDate time.Time -} \ No newline at end of file + InvoiceDate time.Time +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/01/main.go b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/01/main.go index 0fd54851..578a2bd9 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/01/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/01/main.go @@ -2,9 +2,9 @@ package main import "fmt" -func main() { +func main() { ch := make(chan string) - fmt.Println(<-ch) // program waits here to drain the channel - // since there is nothing to receive from the channel - // our program is in a deadlock -} \ No newline at end of file + fmt.Println(<-ch) // program waits here to drain the channel + // since there is nothing to receive from the channel + // our program is in a deadlock +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/02/main.go b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/02/main.go index 50b83409..612d39b5 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/02/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/02/main.go @@ -7,10 +7,10 @@ import ( func main() { ch := make(chan string) - ch <- "Hello" // program waits here until channel is drained - // since our main thread is waiting on the above line - // the main thread never gets to the statement below that drains the channel - // our program is in a deadlock + ch <- "Hello" // program waits here until channel is drained + // since our main thread is waiting on the above line + // the main thread never gets to the statement below that drains the channel + // our program is in a deadlock fmt.Println(<-ch) } @@ -20,4 +20,4 @@ the capacity to store messages which will allow the sender & receiver to not have to wait on each other we'll see this in the next file, 03 this is known as creating a "buffered" channel -*/ \ No newline at end of file +*/ diff --git a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/03_buffered-channel/main.go b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/03_buffered-channel/main.go index cca2e066..6085fae3 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/03_buffered-channel/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/03_buffered-channel/main.go @@ -1,13 +1,13 @@ package main - + import ( - "fmt" + "fmt" ) -func main() { - ch := make(chan string,1) - +func main() { + ch := make(chan string, 1) + ch <- "Hello" - + fmt.Println(<-ch) -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/04/main.go b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/04/main.go index 5a4f8e1d..ad485681 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/04/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/01_print-hello/04/main.go @@ -1,17 +1,17 @@ package main - + import ( - "fmt" + "fmt" ) -func main() { - ch := make(chan string,1) - +func main() { + ch := make(chan string, 1) + ch <- "Hello" - + fmt.Println(<-ch) - + ch <- "Go" - + fmt.Println(<-ch) -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/02_buffering/main.go b/36_concurrency/01_concurrency_PS/04_channels/02_buffering/main.go index ef853f86..ed158bc6 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/02_buffering/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/02_buffering/main.go @@ -1,8 +1,8 @@ package main import ( - "strings" "fmt" + "strings" ) func main() { @@ -16,8 +16,8 @@ func main() { ch <- word } - for i:=0; i < len(words); i++ { + for i := 0; i < len(words); i++ { fmt.Print(<-ch + " ") } -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/01/main.go b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/01/main.go index e81a192f..58591704 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/01/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/01/main.go @@ -1,8 +1,8 @@ package main import ( - "strings" "fmt" + "strings" ) func main() { @@ -20,9 +20,8 @@ func main() { // closing a channel only closes the ability to send onto the channel // data on the channel remains on channel // and channel can still be received from - for i:=0; i < len(words); i++ { + for i := 0; i < len(words); i++ { fmt.Print(<-ch + " ") } } - diff --git a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/02_no-sending-on-closed-channel/main.go b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/02_no-sending-on-closed-channel/main.go index bc930fea..1227b8db 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/02_no-sending-on-closed-channel/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/02_no-sending-on-closed-channel/main.go @@ -1,8 +1,8 @@ package main import ( - "strings" "fmt" + "strings" ) func main() { @@ -20,7 +20,7 @@ func main() { // closing a channel only closes the ability to send onto the channel // data on the channel remains on channel // and channel can still be received from - for i:=0; i < len(words); i++ { + for i := 0; i < len(words); i++ { fmt.Print(<-ch + " ") } @@ -28,4 +28,3 @@ func main() { ch <- "test" } - diff --git a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/03_deadlock/main.go b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/03_deadlock/main.go index 4e5fbc77..c741a55a 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/03_deadlock/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/03_deadlock/main.go @@ -1,32 +1,32 @@ package main - + import ( - "strings" "fmt" + "strings" ) -func main() { +func main() { phrase := "These are the times that try men's souls\n" - + words := strings.Split(phrase, " ") - + ch := make(chan string, len(words)) - + for _, word := range words { ch <- word } - + for { - if msg, ok := <- ch; ok { // we check to see if channel is closed + if msg, ok := <-ch; ok { // we check to see if channel is closed fmt.Print(msg + " ") } else { break } } - // but we haven't closed the channel yet - // so the for loop on line 19 - // loops through all of the words on the channel - // then waits for another word to be put on the channel - // and as no word is ever going to be put on the channel - // program is in deadlock -} \ No newline at end of file + // but we haven't closed the channel yet + // so the for loop on line 19 + // loops through all of the words on the channel + // then waits for another word to be put on the channel + // and as no word is ever going to be put on the channel + // program is in deadlock +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/04/main.go b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/04/main.go index b957de4c..b5155ba3 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/04/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/04/main.go @@ -1,29 +1,29 @@ package main - + import ( - "strings" "fmt" + "strings" ) -func main() { +func main() { phrase := "These are the times that try men's souls\n" - + words := strings.Split(phrase, " ") - + ch := make(chan string, len(words)) - + for _, word := range words { ch <- word } - + close(ch) // closing the channel removes deadlock - + for { - if msg, ok := <- ch; ok { // when channel is closed - fmt.Print(msg + " ") // this for loop will no longer be waiting - } else { // to receive something from channel - break // the loop will break + if msg, ok := <-ch; ok { // when channel is closed + fmt.Print(msg + " ") // this for loop will no longer be waiting + } else { // to receive something from channel + break // the loop will break } } - -} \ No newline at end of file + +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/05_idiomatic/main.go b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/05_idiomatic/main.go index fc9419cf..be16f36a 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/05_idiomatic/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/03_closing-channel/05_idiomatic/main.go @@ -1,26 +1,26 @@ package main - + import ( - "strings" "fmt" + "strings" ) -func main() { +func main() { phrase := "These are the times that try men's souls\n" - + words := strings.Split(phrase, " ") - + ch := make(chan string, len(words)) - + for _, word := range words { ch <- word } - + close(ch) - + for msg := range ch { - fmt.Print(msg + " ") + fmt.Print(msg + " ") } // range knows to stop looping // when there is nothing left in a closed channel -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go b/36_concurrency/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go index e90d91ca..1c460ecf 100644 --- a/36_concurrency/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go +++ b/36_concurrency/01_concurrency_PS/04_channels/04_listening-on-multiple-channels/01/main.go @@ -10,9 +10,9 @@ func main() { errCh := make(chan FailedMessage, 1) select { - case receivedMsg := <- msgCh: + case receivedMsg := <-msgCh: fmt.Println(receivedMsg) - case receivedError := <- errCh: + case receivedError := <-errCh: fmt.Println(receivedError) default: fmt.Println("No messages received") @@ -21,45 +21,45 @@ func main() { } type Message struct { - To []string - From string + To []string + From string Content string } type FailedMessage struct { - ErrorMessage string + ErrorMessage string OriginalMessage Message } /* 3.5.1 - demo setup -package main - +package main + import ( "fmt" ) -func main() { - +func main() { + msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + 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{}, } - + msgCh <- msg errCh <- failedMessage - + fmt.Println(<-msgCh) fmt.Println(<-errCh) - + } type Message struct { @@ -75,32 +75,32 @@ type FailedMessage struct { */ /* 3.5.2 - add select, use first -package main - +package main + import ( "fmt" ) -func main() { - +func main() { + msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + msg := Message{ To: []string{"bilbo@underhill.me"}, From: "gandalf@whitecouncil.org", Content: "Keep it secret, keep it safe", } - + msgCh <- msg - + select { case receivedMsg := <- msgCh: fmt.Println(receivedMsg) case receivedError := <- errCh: fmt.Println(receivedError) } - + } type Message struct { @@ -116,37 +116,37 @@ type FailedMessage struct { */ /* 3.5.3 - use second select case -package main - +package main + import ( "fmt" ) -func main() { - +func main() { + msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + 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{}, } errCh <- failedMessage - + select { case receivedMsg := <- msgCh: fmt.Println(receivedMsg) case receivedError := <- errCh: fmt.Println(receivedError) } - + } type Message struct { @@ -162,38 +162,38 @@ type FailedMessage struct { */ /* 3.5.3 - add select, send both messages -package main - +package main + import ( "fmt" -) +) + +func main() { -func main() { - msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + 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{}, } - + msgCh <- msg errCh <- failedMessage - + select { case receivedMsg := <- msgCh: fmt.Println(receivedMsg) case receivedError := <- errCh: fmt.Println(receivedError) } - + } type Message struct { @@ -209,24 +209,24 @@ type FailedMessage struct { */ /* 3.5.4 - send no messages -package main - +package main + import ( "fmt" -) +) + +func main() { -func main() { - msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + select { case receivedMsg := <- msgCh: fmt.Println(receivedMsg) case receivedError := <- errCh: fmt.Println(receivedError) } - + } type Message struct { @@ -242,17 +242,17 @@ type FailedMessage struct { */ /* 3.5.5 - non-blocking select -package main - +package main + import ( "fmt" -) +) + +func main() { -func main() { - msgCh := make(chan Message, 1) errCh := make(chan FailedMessage, 1) - + select { case receivedMsg := <- msgCh: fmt.Println(receivedMsg) @@ -261,7 +261,7 @@ func main() { default: fmt.Println("No messages received") } - + } type Message struct { @@ -274,4 +274,4 @@ type FailedMessage struct { ErrorMessage string OriginalMessage Message } -*/ \ No newline at end of file +*/ diff --git a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/01_no-mutex/main.go b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/01_no-mutex/main.go index 450834b1..99fb92a3 100644 --- a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/01_no-mutex/main.go +++ b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/01_no-mutex/main.go @@ -1,20 +1,20 @@ package main - -import ( + +import ( "fmt" "runtime" ) func main() { runtime.GOMAXPROCS(4) - - for i:=1; i < 10;i++ { - for j:=1; j<10;j++ { + + for i := 1; i < 10; i++ { + for j := 1; j < 10; j++ { go func() { fmt.Printf("%d + %d = %d\n", i, j, i+j) }() } } - + fmt.Scanln() -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/02_mutex/main.go b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/02_mutex/main.go index 465a2377..7d55b1dc 100644 --- a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/02_mutex/main.go +++ b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/02_mutex/main.go @@ -11,9 +11,8 @@ func main() { mutex := new(sync.Mutex) - - for i:=1; i < 10;i++ { - for j:=1; j<10;j++ { + for i := 1; i < 10; i++ { + for j := 1; j < 10; j++ { mutex.Lock() go func() { fmt.Printf("%d + %d = %d\n", i, j, i+j) @@ -23,4 +22,4 @@ func main() { } fmt.Scanln() -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/03_channel_blocking-behavior/main.go b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/03_channel_blocking-behavior/main.go index 489b1bfb..5df73a0a 100644 --- a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/03_channel_blocking-behavior/main.go +++ b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/03_channel_blocking-behavior/main.go @@ -1,22 +1,21 @@ package main - -import ( + +import ( "fmt" "runtime" ) func main() { runtime.GOMAXPROCS(4) - + mutex := make(chan bool, 1) - - - for i:=1; i < 10;i++ { - for j:=1; j<10;j++ { - mutex <- true // puts bool on channel - go func() { + + for i := 1; i < 10; i++ { + for j := 1; j < 10; j++ { + mutex <- true // puts bool on channel + go func() { fmt.Printf("%d + %d = %d\n", i, j, i+j) - <-mutex // takes bool off channel + <-mutex // takes bool off channel }() } } @@ -32,4 +31,4 @@ the program will pause there until the bool that is already on the chennel is ta NOT GOOD PRODUCTION CODE just interesting to see that channels can behave like mutexes -*/ \ No newline at end of file +*/ diff --git a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/04_log-file/main.go b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/04_log-file/main.go index f99c681a..85b1a382 100644 --- a/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/04_log-file/main.go +++ b/36_concurrency/01_concurrency_PS/05_mutex_vs_channels/04_log-file/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "runtime" "os" + "runtime" "time" ) @@ -17,7 +17,7 @@ func main() { go func() { for { - msg, ok := <- logCh + msg, ok := <-logCh if ok { f, _ := os.OpenFile("./log.txt", os.O_APPEND, os.ModeAppend) @@ -30,8 +30,8 @@ func main() { } }() - for i:=1; i < 10;i++ { - for j:=1; j<10;j++ { + for i := 1; i < 10; i++ { + for j := 1; j < 10; j++ { go func(i, j int) { msg := fmt.Sprintf("%d + %d = %d\n", i, j, i+j) logCh <- msg @@ -41,4 +41,4 @@ func main() { } fmt.Scanln() -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/06_events_vs_go-routines/complex.go b/36_concurrency/01_concurrency_PS/06_events_vs_go-routines/complex.go index ad2c811a..3b78fc00 100644 --- a/36_concurrency/01_concurrency_PS/06_events_vs_go-routines/complex.go +++ b/36_concurrency/01_concurrency_PS/06_events_vs_go-routines/complex.go @@ -15,14 +15,14 @@ func main() { go func() { for { - msg := <- handlerOne + msg := <-handlerOne fmt.Println("Handler One: " + msg) } }() go func() { for { - msg := <- handlerTwo + msg := <-handlerTwo fmt.Println("Handler Two: " + msg) } }() @@ -43,7 +43,7 @@ type Button struct { func (this *Button) AddEventListener(event string, responseChannel chan string) { if _, present := this.eventListeners[event]; present { this.eventListeners[event] = - append(this.eventListeners[event], responseChannel) + append(this.eventListeners[event], responseChannel) } else { this.eventListeners[event] = []chan string{responseChannel} } @@ -71,8 +71,8 @@ func (this *Button) TriggerEvent(event string, response string) { } } -func MakeButton()*Button { +func MakeButton() *Button { result := new(Button) result.eventListeners = make(map[string][]chan string) return result -} \ No newline at end of file +} diff --git a/36_concurrency/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go b/36_concurrency/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go index 1f1070f6..67e7a91a 100644 --- a/36_concurrency/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go +++ b/36_concurrency/01_concurrency_PS/07_simulating_callbacks_with_go-routines/main.go @@ -6,7 +6,7 @@ import ( type PurchaseOrder struct { Number int - Value float64 + Value float64 } func SavePO(po *PurchaseOrder, callbackChannel chan *PurchaseOrder) { @@ -23,8 +23,6 @@ func main() { go SavePO(po, ch) - newPo := <- ch + newPo := <-ch fmt.Printf("PO Number: %d\n", newPo.Number) } - - diff --git a/36_concurrency/01_concurrency_PS/08_pipe-filter/main.go b/36_concurrency/01_concurrency_PS/08_pipe-filter/main.go index 928f0e9f..b2603bac 100644 --- a/36_concurrency/01_concurrency_PS/08_pipe-filter/main.go +++ b/36_concurrency/01_concurrency_PS/08_pipe-filter/main.go @@ -11,7 +11,7 @@ func main() { ch := make(chan int) go generate(ch) for { - prime := <-ch // off ch + prime := <-ch // off ch fmt.Println(prime) ch1 := make(chan int) go filter(ch, ch1, prime) @@ -20,8 +20,8 @@ func main() { } func generate(ch chan int) { - for i:=2;;i++ { - ch <- i // onto ch + for i := 2; ; i++ { + ch <- i // onto ch } } @@ -32,4 +32,4 @@ func filter(in, out chan int, prime int) { out <- i } } -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/01_go-routine/01/main.go b/36_concurrency/02_concurrency_CD/01_go-routine/01/main.go index 9be396df..badadabe 100644 --- a/36_concurrency/02_concurrency_CD/01_go-routine/01/main.go +++ b/36_concurrency/02_concurrency_CD/01_go-routine/01/main.go @@ -12,4 +12,4 @@ func main() { go f(0) var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/01_go-routine/02/main.go b/36_concurrency/02_concurrency_CD/01_go-routine/02/main.go index 5b2a7224..4ea75183 100644 --- a/36_concurrency/02_concurrency_CD/01_go-routine/02/main.go +++ b/36_concurrency/02_concurrency_CD/01_go-routine/02/main.go @@ -14,4 +14,4 @@ func main() { } var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/01_go-routine/03/main.go b/36_concurrency/02_concurrency_CD/01_go-routine/03/main.go index b1113f74..c2b8c5cf 100644 --- a/36_concurrency/02_concurrency_CD/01_go-routine/03/main.go +++ b/36_concurrency/02_concurrency_CD/01_go-routine/03/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "time" "math/rand" + "time" ) func f(n int) { @@ -20,4 +20,4 @@ func main() { } var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/02_channels/01/main.go b/36_concurrency/02_concurrency_CD/02_channels/01/main.go index b1151ccd..79abad98 100644 --- a/36_concurrency/02_concurrency_CD/02_channels/01/main.go +++ b/36_concurrency/02_concurrency_CD/02_channels/01/main.go @@ -7,19 +7,19 @@ import ( func pinger(c chan string) { for i := 0; ; i++ { - c <- "ping" // program waits here until channel is drained + c <- "ping" // program waits here until channel is drained } } func ponger(c chan string) { for i := 0; ; i++ { - c <- "pong" // program waits here until channel is drained + c <- "pong" // program waits here until channel is drained } } func printer(c chan string) { for { - msg := <- c + msg := <-c fmt.Println(msg) time.Sleep(time.Second * 1) } @@ -34,4 +34,4 @@ func main() { var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/03/main.go b/36_concurrency/02_concurrency_CD/03/main.go index 20bbce22..01466264 100644 --- a/36_concurrency/02_concurrency_CD/03/main.go +++ b/36_concurrency/02_concurrency_CD/03/main.go @@ -14,4 +14,4 @@ func main() { } var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/04/main.go b/36_concurrency/02_concurrency_CD/04/main.go index b1113f74..c2b8c5cf 100644 --- a/36_concurrency/02_concurrency_CD/04/main.go +++ b/36_concurrency/02_concurrency_CD/04/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "time" "math/rand" + "time" ) func f(n int) { @@ -20,4 +20,4 @@ func main() { } var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/05/main.go b/36_concurrency/02_concurrency_CD/05/main.go index e3dbeab4..07c23fbf 100644 --- a/36_concurrency/02_concurrency_CD/05/main.go +++ b/36_concurrency/02_concurrency_CD/05/main.go @@ -13,7 +13,7 @@ func pinger(c chan string) { func printer(c chan string) { for { - msg := <- c + msg := <-c fmt.Println(msg) time.Sleep(time.Second * 1) } @@ -27,4 +27,4 @@ func main() { var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/06/main.go b/36_concurrency/02_concurrency_CD/06/main.go index 79b32bb6..cb9e8377 100644 --- a/36_concurrency/02_concurrency_CD/06/main.go +++ b/36_concurrency/02_concurrency_CD/06/main.go @@ -19,7 +19,7 @@ func ponger(c chan string) { func printer(c chan string) { for { - msg := <- c + msg := <-c fmt.Println(msg) time.Sleep(time.Second * 1) } @@ -34,4 +34,4 @@ func main() { var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/07/main.go b/36_concurrency/02_concurrency_CD/07/main.go index 79b32bb6..cb9e8377 100644 --- a/36_concurrency/02_concurrency_CD/07/main.go +++ b/36_concurrency/02_concurrency_CD/07/main.go @@ -19,7 +19,7 @@ func ponger(c chan string) { func printer(c chan string) { for { - msg := <- c + msg := <-c fmt.Println(msg) time.Sleep(time.Second * 1) } @@ -34,4 +34,4 @@ func main() { var input string fmt.Scanln(&input) -} \ No newline at end of file +} diff --git a/36_concurrency/02_concurrency_CD/11/main.go b/36_concurrency/02_concurrency_CD/11/main.go index 62122976..24b4ea97 100644 --- a/36_concurrency/02_concurrency_CD/11/main.go +++ b/36_concurrency/02_concurrency_CD/11/main.go @@ -26,5 +26,3 @@ func main() { var input string fmt.Scanln(&input) } - - diff --git a/36_concurrency/04_waitgroup/04_walk/01/main.go b/36_concurrency/04_waitgroup/04_walk/01/main.go index 46ec6dca..d3a6e050 100644 --- a/36_concurrency/04_waitgroup/04_walk/01/main.go +++ b/36_concurrency/04_waitgroup/04_walk/01/main.go @@ -39,5 +39,3 @@ func main() { }) wg.Wait() } - - diff --git a/36_concurrency/04_waitgroup/04_walk/02/main.go b/36_concurrency/04_waitgroup/04_walk/02/main.go index f036278f..aa9187a1 100644 --- a/36_concurrency/04_waitgroup/04_walk/02/main.go +++ b/36_concurrency/04_waitgroup/04_walk/02/main.go @@ -41,4 +41,4 @@ func main() { fmt.Println(<-c) } -} \ No newline at end of file +} diff --git a/36_concurrency/04_waitgroup/04_walk/03/main.go b/36_concurrency/04_waitgroup/04_walk/03/main.go index 18ff4048..901a7dfd 100644 --- a/36_concurrency/04_waitgroup/04_walk/03/main.go +++ b/36_concurrency/04_waitgroup/04_walk/03/main.go @@ -54,5 +54,3 @@ func main() { printStep(sumInfoChannel) } - - diff --git a/36_concurrency/04_waitgroup/04_walk/04/main.go b/36_concurrency/04_waitgroup/04_walk/04/main.go index 6a2cb9f1..dd7a21e3 100644 --- a/36_concurrency/04_waitgroup/04_walk/04/main.go +++ b/36_concurrency/04_waitgroup/04_walk/04/main.go @@ -70,4 +70,4 @@ func main() { }() printStep(sumInfoChannel) -} \ No newline at end of file +} diff --git a/37_review-exercises/01_gravatar/main.go b/37_review-exercises/01_gravatar/main.go index 950484a7..7ce33a53 100644 --- a/37_review-exercises/01_gravatar/main.go +++ b/37_review-exercises/01_gravatar/main.go @@ -1,12 +1,12 @@ package main import ( - "fmt" - "strings" "crypto/md5" - "io" "encoding/hex" + "fmt" + "io" "os" + "strings" ) func getGravatarHash(email string) string { diff --git a/37_review-exercises/04_swap-two_pointers/main.go b/37_review-exercises/04_swap-two_pointers/main.go index 99a2510e..e83d0fac 100644 --- a/37_review-exercises/04_swap-two_pointers/main.go +++ b/37_review-exercises/04_swap-two_pointers/main.go @@ -12,4 +12,4 @@ func main() { swap(&x, &y) fmt.Println("x", x) fmt.Println("y", y) -} \ No newline at end of file +} diff --git a/37_review-exercises/06_cat/main.go b/37_review-exercises/06_cat/main.go index 4e3e8edd..8d41fb93 100644 --- a/37_review-exercises/06_cat/main.go +++ b/37_review-exercises/06_cat/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" + "os" ) func main() { @@ -31,4 +31,4 @@ go install step 2 - at command line enter: 06_cat main.go -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/07_copy/main.go b/37_review-exercises/07_copy/main.go index 93832053..8911038f 100644 --- a/37_review-exercises/07_copy/main.go +++ b/37_review-exercises/07_copy/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io/ioutil" + "log" + "os" ) func main() { @@ -37,4 +37,4 @@ go install step 2 - at command line enter: 07_copy main.go -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/01/main.go b/37_review-exercises/08_cp/01/main.go index 2978d42d..e2b492f8 100644 --- a/37_review-exercises/08_cp/01/main.go +++ b/37_review-exercises/08_cp/01/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io/ioutil" + "log" + "os" ) func main() { @@ -41,4 +41,4 @@ go install step 2 - at command line enter: 01 initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/02/main.go b/37_review-exercises/08_cp/02/main.go index c21123f3..8760ad6e 100644 --- a/37_review-exercises/08_cp/02/main.go +++ b/37_review-exercises/08_cp/02/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io/ioutil" + "log" + "os" ) func main() { @@ -46,4 +46,4 @@ go install step 2 - at command line enter: 01_this-does-not-compile initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/03/main.go b/37_review-exercises/08_cp/03/main.go index 6c9afc87..4a55289f 100644 --- a/37_review-exercises/08_cp/03/main.go +++ b/37_review-exercises/08_cp/03/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" - "io/ioutil" "fmt" + "io/ioutil" + "log" + "os" ) func cp(srcName, dstName string) error { @@ -62,4 +62,4 @@ go install step 2 - at command line enter: 03 initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/04_io-copy/main.go b/37_review-exercises/08_cp/04_io-copy/main.go index 8b1d3c31..415ceea1 100644 --- a/37_review-exercises/08_cp/04_io-copy/main.go +++ b/37_review-exercises/08_cp/04_io-copy/main.go @@ -1,10 +1,10 @@ package main import ( - "os" - "log" "fmt" "io" + "log" + "os" ) func cp(srcName, dstName string) error { @@ -53,4 +53,4 @@ go install step 2 - at command line enter: 04_io-copy initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/05_os-write_slice-bytes/main.go b/37_review-exercises/08_cp/05_os-write_slice-bytes/main.go index d4e4f799..08af5383 100644 --- a/37_review-exercises/08_cp/05_os-write_slice-bytes/main.go +++ b/37_review-exercises/08_cp/05_os-write_slice-bytes/main.go @@ -1,8 +1,8 @@ package main import ( - "os" "log" + "os" ) func main() { @@ -37,4 +37,4 @@ go install step 2 - at command line enter: programName initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/06_io-copy_string-NewReader/main.go b/37_review-exercises/08_cp/06_io-copy_string-NewReader/main.go index 3384ca2c..4001f153 100644 --- a/37_review-exercises/08_cp/06_io-copy_string-NewReader/main.go +++ b/37_review-exercises/08_cp/06_io-copy_string-NewReader/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io" + "log" + "os" "strings" ) @@ -19,6 +19,7 @@ func main() { io.Copy(dst, rdr) } + /* io.Copy @@ -32,7 +33,6 @@ func (r *Reader) Read(b []byte) (n int, err error) */ - /* step 1 - at command line enter: diff --git a/37_review-exercises/08_cp/07_io-copy_bufio-NewReader/main.go b/37_review-exercises/08_cp/07_io-copy_bufio-NewReader/main.go index ac04ad70..725ae42f 100644 --- a/37_review-exercises/08_cp/07_io-copy_bufio-NewReader/main.go +++ b/37_review-exercises/08_cp/07_io-copy_bufio-NewReader/main.go @@ -1,11 +1,11 @@ package main import ( - "os" - "log" + "bufio" "fmt" "io" - "bufio" + "log" + "os" ) func cp(srcName, dstName string) error { @@ -56,4 +56,4 @@ go install step 2 - at command line enter: programName initial.txt second.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/08_cp/08_bufio_scanner/main.go b/37_review-exercises/08_cp/08_bufio_scanner/main.go index 2d73c81d..6cf57e17 100644 --- a/37_review-exercises/08_cp/08_bufio_scanner/main.go +++ b/37_review-exercises/08_cp/08_bufio_scanner/main.go @@ -1,9 +1,10 @@ package main + import ( - "fmt" - "os" "bufio" + "fmt" "log" + "os" ) func main() { @@ -19,6 +20,7 @@ func main() { fmt.Println(">>>", line) } } + /* scanners allow us to interact with files line-by-line */ diff --git a/37_review-exercises/11_every-other-word/main.go b/37_review-exercises/11_every-other-word/main.go index fb1971fc..8e01a12c 100644 --- a/37_review-exercises/11_every-other-word/main.go +++ b/37_review-exercises/11_every-other-word/main.go @@ -20,7 +20,7 @@ func main() { scanner.Split(bufio.ScanWords) for scanner.Scan() { word := scanner.Text() - if len(word) > 0 && i % 2 == 0 { + if len(word) > 0 && i%2 == 0 { fmt.Print(strings.ToUpper(word), " ") } else { fmt.Print(word, " ") diff --git a/37_review-exercises/12_count-words/main.go b/37_review-exercises/12_count-words/main.go index 70a811d3..76adeb0e 100644 --- a/37_review-exercises/12_count-words/main.go +++ b/37_review-exercises/12_count-words/main.go @@ -38,4 +38,4 @@ func main() { /* get moby dick from terminal: curl -O http://www.gutenberg.org/files/2701/old/moby10b.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/13_longest-word/main.go b/37_review-exercises/13_longest-word/main.go index ca51d4bd..61f747ae 100644 --- a/37_review-exercises/13_longest-word/main.go +++ b/37_review-exercises/13_longest-word/main.go @@ -35,4 +35,4 @@ func main() { /* get moby dick from terminal: curl -O http://www.gutenberg.org/files/2701/old/moby10b.txt -*/ \ No newline at end of file +*/ diff --git a/37_review-exercises/14_cat-files/01/main.go b/37_review-exercises/14_cat-files/01/main.go index e0184e3d..454a5acd 100644 --- a/37_review-exercises/14_cat-files/01/main.go +++ b/37_review-exercises/14_cat-files/01/main.go @@ -1,9 +1,9 @@ package main import ( - "os" - "log" "io" + "log" + "os" ) func main() { diff --git a/37_review-exercises/14_cat-files/02/main.go b/37_review-exercises/14_cat-files/02/main.go index 31dd400c..7f781722 100644 --- a/37_review-exercises/14_cat-files/02/main.go +++ b/37_review-exercises/14_cat-files/02/main.go @@ -1,8 +1,9 @@ package main + import ( - "os" - "log" "io" + "log" + "os" ) func main() { diff --git a/37_review-exercises/15_csv_state-info/step03_panics/main.go b/37_review-exercises/15_csv_state-info/step03_panics/main.go index 9160fc66..9b23d328 100644 --- a/37_review-exercises/15_csv_state-info/step03_panics/main.go +++ b/37_review-exercises/15_csv_state-info/step03_panics/main.go @@ -39,7 +39,6 @@ func main() { log.Fatalln(err) } - if rowCount == 0 { for idx, column := range record { columns[column] = idx diff --git a/37_review-exercises/15_csv_state-info/step04_parse-state/main.go b/37_review-exercises/15_csv_state-info/step04_parse-state/main.go index b0c3e3dc..348d1812 100644 --- a/37_review-exercises/15_csv_state-info/step04_parse-state/main.go +++ b/37_review-exercises/15_csv_state-info/step04_parse-state/main.go @@ -24,9 +24,9 @@ func parseState(columns map[string]int, record []string) (*state, error) { return nil, err } return &state{ - id: id, - name: name, - abbreviation: abbreviation, + id: id, + name: name, + abbreviation: abbreviation, censusRegionName: censusRegionName, }, nil } @@ -52,7 +52,6 @@ func main() { log.Fatalln(err) } - if rowCount == 0 { for idx, column := range record { columns[column] = idx diff --git a/37_review-exercises/15_csv_state-info/step05_state-lookup/main.go b/37_review-exercises/15_csv_state-info/step05_state-lookup/main.go index 0ff84302..20cc4dbd 100644 --- a/37_review-exercises/15_csv_state-info/step05_state-lookup/main.go +++ b/37_review-exercises/15_csv_state-info/step05_state-lookup/main.go @@ -81,6 +81,7 @@ func main() { } fmt.Println(state) } + /* at terminal: go install diff --git a/37_review-exercises/15_csv_state-info/step06_write-to-html/main.go b/37_review-exercises/15_csv_state-info/step06_write-to-html/main.go index 08a09f91..03f66682 100644 --- a/37_review-exercises/15_csv_state-info/step06_write-to-html/main.go +++ b/37_review-exercises/15_csv_state-info/step06_write-to-html/main.go @@ -102,6 +102,7 @@ func main() { `) } + /* at terminal: go install diff --git a/37_review-exercises/16_csv_stock-prices/step01_stdout/main.go b/37_review-exercises/16_csv_stock-prices/step01_stdout/main.go index 629d2424..39bb10db 100644 --- a/37_review-exercises/16_csv_stock-prices/step01_stdout/main.go +++ b/37_review-exercises/16_csv_stock-prices/step01_stdout/main.go @@ -42,6 +42,3 @@ func main() { } } - - - diff --git a/37_review-exercises/16_csv_stock-prices/step02_html/main.go b/37_review-exercises/16_csv_stock-prices/step02_html/main.go index f5914758..7d26738e 100644 --- a/37_review-exercises/16_csv_stock-prices/step02_html/main.go +++ b/37_review-exercises/16_csv_stock-prices/step02_html/main.go @@ -65,4 +65,4 @@ func main() { `) -} \ No newline at end of file +} diff --git a/37_review-exercises/16_csv_stock-prices/step03_charting/main.go b/37_review-exercises/16_csv_stock-prices/step03_charting/main.go index 2d605045..5312b3d0 100644 --- a/37_review-exercises/16_csv_stock-prices/step03_charting/main.go +++ b/37_review-exercises/16_csv_stock-prices/step03_charting/main.go @@ -125,6 +125,3 @@ func main() { `) } - - - diff --git a/37_review-exercises/17_MD5-checksum/main.go b/37_review-exercises/17_MD5-checksum/main.go index df892757..c84ce5cb 100644 --- a/37_review-exercises/17_MD5-checksum/main.go +++ b/37_review-exercises/17_MD5-checksum/main.go @@ -1,10 +1,10 @@ package main import ( + "crypto/md5" "fmt" "io" "os" - "crypto/md5" ) func main() { @@ -17,4 +17,4 @@ func main() { h := md5.New() io.Copy(h, f) fmt.Printf("%x\n", h.Sum(nil)) -} \ No newline at end of file +} diff --git a/37_review-exercises/18_Walk-dir/main.go b/37_review-exercises/18_Walk-dir/main.go index a074efb2..e2cc8fa3 100644 --- a/37_review-exercises/18_Walk-dir/main.go +++ b/37_review-exercises/18_Walk-dir/main.go @@ -32,10 +32,7 @@ func main() { }) } - - - /* walk is recursive readdir is not - */ +*/ diff --git a/38_JSON/01/main.go b/38_JSON/01/main.go index 55361c84..d0078b6a 100644 --- a/38_JSON/01/main.go +++ b/38_JSON/01/main.go @@ -20,5 +20,5 @@ func main() { } fmt.Println(obj) fmt.Println(obj["name"]) - fmt.Printf("%T\n",obj["name"]) + fmt.Printf("%T\n", obj["name"]) } diff --git a/38_JSON/02/main.go b/38_JSON/02/main.go index 92471521..4990c3fa 100644 --- a/38_JSON/02/main.go +++ b/38_JSON/02/main.go @@ -22,6 +22,6 @@ func main() { fmt.Println(obj) fmt.Println(obj["name"]) fmt.Println(obj["age"]) - fmt.Printf("%T\n",obj["name"]) - fmt.Printf("%T\n",obj["age"]) + fmt.Printf("%T\n", obj["name"]) + fmt.Printf("%T\n", obj["age"]) } diff --git a/38_JSON/06/main.go b/38_JSON/06/main.go index 30a4333d..64321ca3 100644 --- a/38_JSON/06/main.go +++ b/38_JSON/06/main.go @@ -1,4 +1,5 @@ package main + import ( "encoding/json" "fmt" diff --git a/38_JSON/08/main.go b/38_JSON/08/main.go index ff5915e3..2bdc6a5f 100644 --- a/38_JSON/08/main.go +++ b/38_JSON/08/main.go @@ -1,4 +1,5 @@ package main + import ( "encoding/json" "fmt" diff --git a/38_JSON/11/main.go b/38_JSON/11/main.go index fa8ed811..e3bc6a6b 100644 --- a/38_JSON/11/main.go +++ b/38_JSON/11/main.go @@ -31,6 +31,5 @@ func main() { } - // this code doesn't run -// just captured in lecture \ No newline at end of file +// just captured in lecture diff --git a/38_JSON/12/main.go b/38_JSON/12/main.go index 01cc9bf5..db35a549 100644 --- a/38_JSON/12/main.go +++ b/38_JSON/12/main.go @@ -21,4 +21,4 @@ func main() { panic(err) } fmt.Println(obj) -} \ No newline at end of file +} diff --git a/38_JSON/13/main.go b/38_JSON/13/main.go index d1c84af6..ad5fe3b6 100644 --- a/38_JSON/13/main.go +++ b/38_JSON/13/main.go @@ -23,4 +23,4 @@ func main() { panic(err) } fmt.Println(obj) -} \ No newline at end of file +} diff --git a/38_JSON/14/main.go b/38_JSON/14/main.go index ecf4f330..8d12a06a 100644 --- a/38_JSON/14/main.go +++ b/38_JSON/14/main.go @@ -2,10 +2,10 @@ package main import ( "encoding/csv" -// "fmt" + // "fmt" + "encoding/json" "log" "os" - "encoding/json" ) func main() { @@ -26,7 +26,6 @@ func main() { log.Fatalln("couldn't readall", err.Error()) } - // convert to JSON b, err := json.Marshal(data) if err != nil { @@ -35,7 +34,6 @@ func main() { // show os.Stdout.Write(b) -// fmt.Println(b) - + // fmt.Println(b) } diff --git a/38_JSON/15_exercise_csv-to-JSON/01/main.go b/38_JSON/15_exercise_csv-to-JSON/01/main.go index 46102d42..18ff1aea 100644 --- a/38_JSON/15_exercise_csv-to-JSON/01/main.go +++ b/38_JSON/15_exercise_csv-to-JSON/01/main.go @@ -2,10 +2,10 @@ package main import ( "encoding/csv" -// "fmt" + // "fmt" + "encoding/json" "log" "os" - "encoding/json" ) func main() { @@ -26,7 +26,6 @@ func main() { log.Fatalln("couldn't readall", err.Error()) } - // convert to JSON b, err := json.Marshal(data) if err != nil { @@ -35,7 +34,6 @@ func main() { // show os.Stdout.Write(b) -// fmt.Println(b) - + // fmt.Println(b) } diff --git a/38_JSON/16/main.go b/38_JSON/16/main.go index f3366300..6764a7bd 100644 --- a/38_JSON/16/main.go +++ b/38_JSON/16/main.go @@ -2,19 +2,19 @@ package main import ( "encoding/json" - "log" "fmt" + "log" "os" ) type Article struct { - Name string + Name string draft bool } func main() { - myArticle := Article { - Name: "Once And Then Again", + myArticle := Article{ + Name: "Once And Then Again", draft: false, } diff --git a/38_JSON/17/main.go b/38_JSON/17/main.go index fd163516..6e4d5fdf 100644 --- a/38_JSON/17/main.go +++ b/38_JSON/17/main.go @@ -49,6 +49,3 @@ func main() { } } - - - diff --git a/39_packages/hello/bye.go b/39_packages/hello/bye.go index 8b21ad15..0459cfda 100644 --- a/39_packages/hello/bye.go +++ b/39_packages/hello/bye.go @@ -16,4 +16,4 @@ func looper(str string) string { } fmt.Println(x) return newString -} \ No newline at end of file +} diff --git a/39_packages/hello/hello.go b/39_packages/hello/hello.go index 53cd61d8..90413f48 100644 --- a/39_packages/hello/hello.go +++ b/39_packages/hello/hello.go @@ -4,4 +4,4 @@ import "fmt" func Hello() { fmt.Println("Hello") -} \ No newline at end of file +} diff --git a/40_testing/01/example/sum_test.go b/40_testing/01/example/sum_test.go index 3b73b32c..07e214db 100644 --- a/40_testing/01/example/sum_test.go +++ b/40_testing/01/example/sum_test.go @@ -4,8 +4,8 @@ import "testing" func TestSum(t *testing.T) { var n int - n = Sum(1,2) + n = Sum(1, 2) if n != 3 { t.Error("Expected 3, got ", n) } -} \ No newline at end of file +} diff --git a/40_testing/02/example/sum_test.go b/40_testing/02/example/sum_test.go index 58004def..d9a00def 100644 --- a/40_testing/02/example/sum_test.go +++ b/40_testing/02/example/sum_test.go @@ -4,13 +4,13 @@ import "testing" type testpair struct { values []int - sum int + sum int } var tests = []testpair{ - { []int{1,2}, 3 }, - { []int{1,1,1,1,1,1}, 6 }, - { []int{-1,1}, 0 }, + {[]int{1, 2}, 3}, + {[]int{1, 1, 1, 1, 1, 1}, 6}, + {[]int{-1, 1}, 0}, } func TestSum(t *testing.T) { @@ -25,4 +25,3 @@ func TestSum(t *testing.T) { } } } - diff --git a/41_TCP/03_dial/main.go b/41_TCP/03_dial/main.go index b435abd9..3f0bebf8 100644 --- a/41_TCP/03_dial/main.go +++ b/41_TCP/03_dial/main.go @@ -18,4 +18,4 @@ func main() { } -// see "notes.txt" to run this \ No newline at end of file +// see "notes.txt" to run this diff --git a/41_TCP/04_echo-server/v01/main.go b/41_TCP/04_echo-server/v01/main.go index b0c32b60..ef4f5389 100644 --- a/41_TCP/04_echo-server/v01/main.go +++ b/41_TCP/04_echo-server/v01/main.go @@ -30,6 +30,3 @@ func main() { conn.Close() } } - - - diff --git a/41_TCP/04_echo-server/v03/main.go b/41_TCP/04_echo-server/v03/main.go index 4eebf81b..ffcb5e80 100644 --- a/41_TCP/04_echo-server/v03/main.go +++ b/41_TCP/04_echo-server/v03/main.go @@ -1,8 +1,8 @@ package main import ( - "net" "io" + "net" ) func main() { @@ -24,6 +24,3 @@ func main() { conn.Close() } } - - - diff --git a/41_TCP/04_echo-server/v04/main.go b/41_TCP/04_echo-server/v04/main.go index d773a076..012df981 100644 --- a/41_TCP/04_echo-server/v04/main.go +++ b/41_TCP/04_echo-server/v04/main.go @@ -1,8 +1,8 @@ package main import ( - "net" "io" + "net" ) func main() { @@ -25,6 +25,3 @@ func main() { }() } } - - - diff --git a/41_TCP/05_redis-clone/i01/main.go b/41_TCP/05_redis-clone/i01/main.go index 9944f7da..5373d6be 100644 --- a/41_TCP/05_redis-clone/i01/main.go +++ b/41_TCP/05_redis-clone/i01/main.go @@ -1,10 +1,10 @@ package main import ( - "net" - "log" "bufio" "fmt" + "log" + "net" ) func handle(conn net.Conn) { @@ -19,7 +19,7 @@ func handle(conn net.Conn) { func main() { li, err := net.Listen("tcp", ":9000") - if err != nil{ + if err != nil { log.Fatalln(err) } defer li.Close() diff --git a/41_TCP/05_redis-clone/i03/main.go b/41_TCP/05_redis-clone/i03/main.go index 25947135..cd8252d2 100644 --- a/41_TCP/05_redis-clone/i03/main.go +++ b/41_TCP/05_redis-clone/i03/main.go @@ -2,11 +2,11 @@ package main import ( "bufio" + "fmt" "io" "log" "net" "strings" - "fmt" ) var data = make(map[string]string) diff --git a/41_TCP/05_redis-clone/i04/main.go b/41_TCP/05_redis-clone/i04/main.go index 851dde7b..a1f1cf76 100644 --- a/41_TCP/05_redis-clone/i04/main.go +++ b/41_TCP/05_redis-clone/i04/main.go @@ -2,11 +2,11 @@ package main import ( "bufio" + "fmt" "io" "log" "net" "strings" - "fmt" ) var data = make(map[string]string) diff --git a/41_TCP/05_redis-clone/i05_code-issue/main.go b/41_TCP/05_redis-clone/i05_code-issue/main.go index 0cf621d8..90a00f62 100644 --- a/41_TCP/05_redis-clone/i05_code-issue/main.go +++ b/41_TCP/05_redis-clone/i05_code-issue/main.go @@ -2,11 +2,11 @@ package main import ( "bufio" + "fmt" "io" "log" "net" "strings" - "fmt" ) var data = make(map[string]string) diff --git a/41_TCP/05_redis-clone/i06/main.go b/41_TCP/05_redis-clone/i06/main.go index 35f217b7..9dbad8a8 100644 --- a/41_TCP/05_redis-clone/i06/main.go +++ b/41_TCP/05_redis-clone/i06/main.go @@ -90,4 +90,4 @@ func main() { go handle(commands, conn) } -} \ No newline at end of file +} diff --git a/41_TCP/06_rot13-server/v01-todd/main.go b/41_TCP/06_rot13-server/v01-todd/main.go index 2035ff1c..0b94f805 100644 --- a/41_TCP/06_rot13-server/v01-todd/main.go +++ b/41_TCP/06_rot13-server/v01-todd/main.go @@ -1,9 +1,9 @@ package main import ( - "net" - "fmt" "bufio" + "fmt" + "net" "strings" ) @@ -29,15 +29,15 @@ func main() { // ascii 97 - 122 /// 109 + 13 = 122 if v <= 109 { - rot13[k] = v+13 + rot13[k] = v + 13 } else { // 110 + 13 = 123 //123 - 26 = 97 - rot13[k] = v-26+13 + rot13[k] = v - 26 + 13 } } fmt.Fprintf(conn, "rot13: %s\n", rot13) - } + } } -} \ No newline at end of file +} diff --git a/41_TCP/06_rot13-server/v02-caleb/main.go b/41_TCP/06_rot13-server/v02-caleb/main.go index 4d6832fc..fbbb9abf 100644 --- a/41_TCP/06_rot13-server/v02-caleb/main.go +++ b/41_TCP/06_rot13-server/v02-caleb/main.go @@ -53,4 +53,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/41_TCP/06_rot13-server/v03-daniel/main.go b/41_TCP/06_rot13-server/v03-daniel/main.go index 7c10964a..b72d593c 100644 --- a/41_TCP/06_rot13-server/v03-daniel/main.go +++ b/41_TCP/06_rot13-server/v03-daniel/main.go @@ -48,6 +48,3 @@ func main() { go handleConn(conn) } } - - - diff --git a/41_TCP/07_chat-server/main.go b/41_TCP/07_chat-server/main.go index 167b2fdd..320d46f4 100644 --- a/41_TCP/07_chat-server/main.go +++ b/41_TCP/07_chat-server/main.go @@ -112,4 +112,4 @@ func main() { } go handleConn(chatServer, conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/01_header/main.go b/42_HTTP/01_header/main.go index 1760f058..1c04ba0e 100644 --- a/42_HTTP/01_header/main.go +++ b/42_HTTP/01_header/main.go @@ -30,6 +30,3 @@ func main() { go handleConn(conn) } } - - - diff --git a/42_HTTP/02_http-server/i01/main.go b/42_HTTP/02_http-server/i01/main.go index b0979b8e..0b5891a4 100644 --- a/42_HTTP/02_http-server/i01/main.go +++ b/42_HTTP/02_http-server/i01/main.go @@ -41,4 +41,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i02/main.go b/42_HTTP/02_http-server/i02/main.go index c9250b7c..388278d6 100644 --- a/42_HTTP/02_http-server/i02/main.go +++ b/42_HTTP/02_http-server/i02/main.go @@ -45,4 +45,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i03/main.go b/42_HTTP/02_http-server/i03/main.go index 4991469c..ebce6acb 100644 --- a/42_HTTP/02_http-server/i03/main.go +++ b/42_HTTP/02_http-server/i03/main.go @@ -54,4 +54,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i04_POST/main.go b/42_HTTP/02_http-server/i04_POST/main.go index 7abfe89a..83960a6c 100644 --- a/42_HTTP/02_http-server/i04_POST/main.go +++ b/42_HTTP/02_http-server/i04_POST/main.go @@ -68,4 +68,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i05_not-writing_error-in-code/main.go b/42_HTTP/02_http-server/i05_not-writing_error-in-code/main.go index 3b1ab427..583dd061 100644 --- a/42_HTTP/02_http-server/i05_not-writing_error-in-code/main.go +++ b/42_HTTP/02_http-server/i05_not-writing_error-in-code/main.go @@ -6,8 +6,8 @@ import ( "io" "log" "net" - "strings" "strconv" + "strings" ) func handleConn(conn net.Conn) { @@ -85,4 +85,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i06_PLAIN-TEXT/main.go b/42_HTTP/02_http-server/i06_PLAIN-TEXT/main.go index ceda3a9e..6165278a 100644 --- a/42_HTTP/02_http-server/i06_PLAIN-TEXT/main.go +++ b/42_HTTP/02_http-server/i06_PLAIN-TEXT/main.go @@ -66,4 +66,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/02_http-server/i07_Location/main.go b/42_HTTP/02_http-server/i07_Location/main.go index 827b3419..0482be01 100644 --- a/42_HTTP/02_http-server/i07_Location/main.go +++ b/42_HTTP/02_http-server/i07_Location/main.go @@ -67,4 +67,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/42_HTTP/03_http-server_return-URL/main.go b/42_HTTP/03_http-server_return-URL/main.go index 4d44795b..5666c12e 100644 --- a/42_HTTP/03_http-server_return-URL/main.go +++ b/42_HTTP/03_http-server_return-URL/main.go @@ -56,4 +56,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/43_HTTP-server/01/i01/main.go b/43_HTTP-server/01/i01/main.go index 51ffe815..f69ee058 100644 --- a/43_HTTP-server/01/i01/main.go +++ b/43_HTTP-server/01/i01/main.go @@ -14,4 +14,4 @@ func main() { var h MyHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/01/i02/main.go b/43_HTTP-server/01/i02/main.go index 14e88d74..7c89f262 100644 --- a/43_HTTP-server/01/i02/main.go +++ b/43_HTTP-server/01/i02/main.go @@ -15,4 +15,4 @@ func main() { var h MyHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/02_requestURI/01/main.go b/43_HTTP-server/02_requestURI/01/main.go index 808f70bd..0f14c63b 100644 --- a/43_HTTP-server/02_requestURI/01/main.go +++ b/43_HTTP-server/02_requestURI/01/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) type myHandler int @@ -11,9 +11,8 @@ func (h myHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { io.WriteString(resp, req.URL.RequestURI()) } - func main() { var h myHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/02_requestURI/02/main.go b/43_HTTP-server/02_requestURI/02/main.go index 0ee12bcd..1da06d93 100644 --- a/43_HTTP-server/02_requestURI/02/main.go +++ b/43_HTTP-server/02_requestURI/02/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) type myHandler int @@ -11,9 +11,8 @@ func (h myHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) { io.WriteString(resp, req.RequestURI) } - func main() { var h myHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/03_restful/01/main.go b/43_HTTP-server/03_restful/01/main.go index 58c6eb50..fd71f0d1 100644 --- a/43_HTTP-server/03_restful/01/main.go +++ b/43_HTTP-server/03_restful/01/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) type myHandler int @@ -16,9 +16,8 @@ func (h myHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { } } - func main() { var h myHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/03_restful/02/main.go b/43_HTTP-server/03_restful/02/main.go index db8bae5e..42fedf2f 100644 --- a/43_HTTP-server/03_restful/02/main.go +++ b/43_HTTP-server/03_restful/02/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) type myHandler int @@ -17,9 +17,8 @@ func (h myHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { } } - func main() { var h myHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/43_HTTP-server/03_restful/03/main.go b/43_HTTP-server/03_restful/03/main.go index 6e6c3e18..59481325 100644 --- a/43_HTTP-server/03_restful/03/main.go +++ b/43_HTTP-server/03_restful/03/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) type myHandler int @@ -17,9 +17,8 @@ func (h myHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) { } } - func main() { var h myHandler http.ListenAndServe(":9000", h) -} \ No newline at end of file +} diff --git a/44_MUX_routing/01/main.go b/44_MUX_routing/01/main.go index 1b4cf59f..2993f8ab 100644 --- a/44_MUX_routing/01/main.go +++ b/44_MUX_routing/01/main.go @@ -37,4 +37,4 @@ if route ends in no-slash /dog it only includes that - */ +*/ diff --git a/44_MUX_routing/02/main.go b/44_MUX_routing/02/main.go index 74ff2161..bb15eecf 100644 --- a/44_MUX_routing/02/main.go +++ b/44_MUX_routing/02/main.go @@ -37,4 +37,4 @@ if route ends in no-slash /dog it only includes that - */ +*/ diff --git a/44_MUX_routing/03/main.go b/44_MUX_routing/03/main.go index 1b4cf59f..2993f8ab 100644 --- a/44_MUX_routing/03/main.go +++ b/44_MUX_routing/03/main.go @@ -37,4 +37,4 @@ if route ends in no-slash /dog it only includes that - */ +*/ diff --git a/44_MUX_routing/04/main.go b/44_MUX_routing/04/main.go index a7513e53..7ee781eb 100644 --- a/44_MUX_routing/04/main.go +++ b/44_MUX_routing/04/main.go @@ -28,4 +28,4 @@ func main() { mux.Handle("/cat/", cat) http.ListenAndServe(":9000", mux) -} \ No newline at end of file +} diff --git a/44_MUX_routing/06_HandleFunc/main.go b/44_MUX_routing/06_HandleFunc/main.go index ba88a85e..a7ffc789 100644 --- a/44_MUX_routing/06_HandleFunc/main.go +++ b/44_MUX_routing/06_HandleFunc/main.go @@ -18,4 +18,4 @@ func main() { }) http.ListenAndServe(":9000", mux) -} \ No newline at end of file +} diff --git a/44_MUX_routing/07_HandleFunc/main.go b/44_MUX_routing/07_HandleFunc/main.go index 855eeb29..76a49d73 100644 --- a/44_MUX_routing/07_HandleFunc/main.go +++ b/44_MUX_routing/07_HandleFunc/main.go @@ -5,7 +5,6 @@ import ( "net/http" ) - func upTown(res http.ResponseWriter, req *http.Request) { io.WriteString(res, "doggy doggy doggy") } @@ -21,4 +20,4 @@ func main() { mux.HandleFunc("/cat/", youUp) http.ListenAndServe(":9000", mux) -} \ No newline at end of file +} diff --git a/44_MUX_routing/08_HandleFunc/main.go b/44_MUX_routing/08_HandleFunc/main.go index 431f0f78..f243e72b 100644 --- a/44_MUX_routing/08_HandleFunc/main.go +++ b/44_MUX_routing/08_HandleFunc/main.go @@ -5,7 +5,6 @@ import ( "net/http" ) - func upTown(res http.ResponseWriter, req *http.Request) { io.WriteString(res, "doggy doggy doggy") } @@ -20,4 +19,4 @@ func main() { http.HandleFunc("/cat/", youUp) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/01/main.go b/45_serving-files/01/main.go index fa894748..a8959fd0 100644 --- a/45_serving-files/01/main.go +++ b/45_serving-files/01/main.go @@ -24,4 +24,4 @@ func upTown(res http.ResponseWriter, req *http.Request) { func main() { http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/02/main.go b/45_serving-files/02/main.go index 4b558f26..0667d9fa 100644 --- a/45_serving-files/02/main.go +++ b/45_serving-files/02/main.go @@ -23,4 +23,4 @@ func upTown(res http.ResponseWriter, req *http.Request) { func main() { http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/03/main.go b/45_serving-files/03/main.go index 73381a04..1fa58468 100644 --- a/45_serving-files/03/main.go +++ b/45_serving-files/03/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "io" "net/http" "strings" - "fmt" ) func upTown(res http.ResponseWriter, req *http.Request) { @@ -22,9 +22,9 @@ func upTown(res http.ResponseWriter, req *http.Request) { } func main() { - http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request){ + http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { fmt.Println(req.URL) }) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/04_io-Copy/main.go b/45_serving-files/04_io-Copy/main.go index dc7ac511..00620535 100644 --- a/45_serving-files/04_io-Copy/main.go +++ b/45_serving-files/04_io-Copy/main.go @@ -3,8 +3,8 @@ package main import ( "io" "net/http" - "strings" "os" + "strings" ) func upTown(res http.ResponseWriter, req *http.Request) { @@ -36,4 +36,4 @@ func main() { http.HandleFunc("/toby.jpg", dogPic) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/05_ServeContent/main.go b/45_serving-files/05_ServeContent/main.go index b5e256ab..adc919fa 100644 --- a/45_serving-files/05_ServeContent/main.go +++ b/45_serving-files/05_ServeContent/main.go @@ -3,8 +3,8 @@ package main import ( "io" "net/http" - "strings" "os" + "strings" ) func upTown(res http.ResponseWriter, req *http.Request) { @@ -42,4 +42,4 @@ func main() { http.HandleFunc("/toby.jpg", dogPic) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/06_ServeFile/main.go b/45_serving-files/06_ServeFile/main.go index 6a6e8da2..86ef2f4b 100644 --- a/45_serving-files/06_ServeFile/main.go +++ b/45_serving-files/06_ServeFile/main.go @@ -28,4 +28,4 @@ func main() { http.HandleFunc("/toby.jpg", dogPic) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/07_FileServer/main.go b/45_serving-files/07_FileServer/main.go index 6543d5df..b4f026c5 100644 --- a/45_serving-files/07_FileServer/main.go +++ b/45_serving-files/07_FileServer/main.go @@ -24,4 +24,4 @@ func main() { http.Handle("/", http.FileServer(http.Dir("."))) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/08_FileServer/main.go b/45_serving-files/08_FileServer/main.go index 56909f7f..c478c641 100644 --- a/45_serving-files/08_FileServer/main.go +++ b/45_serving-files/08_FileServer/main.go @@ -24,4 +24,4 @@ func main() { http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets")))) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/45_serving-files/09_FileServer/main.go b/45_serving-files/09_FileServer/main.go index 819bd2d2..e2d72ed2 100644 --- a/45_serving-files/09_FileServer/main.go +++ b/45_serving-files/09_FileServer/main.go @@ -24,4 +24,4 @@ func main() { http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets")))) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/46_errata/05_ServeFile/main.go b/46_errata/05_ServeFile/main.go index 6a6e8da2..86ef2f4b 100644 --- a/46_errata/05_ServeFile/main.go +++ b/46_errata/05_ServeFile/main.go @@ -28,4 +28,4 @@ func main() { http.HandleFunc("/toby.jpg", dogPic) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/47_templates/01_text-templates/03/main.go b/47_templates/01_text-templates/03/main.go index e6ce98df..86ca4718 100644 --- a/47_templates/01_text-templates/03/main.go +++ b/47_templates/01_text-templates/03/main.go @@ -16,5 +16,3 @@ func main() { log.Fatalln(err) } } - - diff --git a/47_templates/02_html-templates/04/main.go b/47_templates/02_html-templates/04/main.go index 3507aad9..a727fbbc 100644 --- a/47_templates/02_html-templates/04/main.go +++ b/47_templates/02_html-templates/04/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "html/template" "log" "os" - "fmt" ) type Page struct { diff --git a/47_templates/02_html-templates/05/main.go b/47_templates/02_html-templates/05/main.go index 47707e71..6aa824dc 100644 --- a/47_templates/02_html-templates/05/main.go +++ b/47_templates/02_html-templates/05/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "html/template" "log" "os" - "fmt" ) type Page struct { diff --git a/47_templates/x03_exercises/03_template_csv-parse/main.go b/47_templates/x03_exercises/03_template_csv-parse/main.go index 1c837fac..62464a38 100644 --- a/47_templates/x03_exercises/03_template_csv-parse/main.go +++ b/47_templates/x03_exercises/03_template_csv-parse/main.go @@ -1,10 +1,10 @@ package main import ( + "github.com/goestoeleven/GolangTraining/47_templates/04_template_csv-parse/parse" "html/template" "log" "net/http" - "github.com/goestoeleven/GolangTraining/47_templates/04_template_csv-parse/parse" ) func main() { diff --git a/48_passing-data/01_URL-values/main.go b/48_passing-data/01_URL-values/main.go index aa6f472a..aec94fc2 100644 --- a/48_passing-data/01_URL-values/main.go +++ b/48_passing-data/01_URL-values/main.go @@ -1,20 +1,18 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { key := "q" val := req.URL.Query().Get(key) - io.WriteString(res, "Do my search:" + val) + io.WriteString(res, "Do my search:"+val) }) http.ListenAndServe(":9000", nil) } // visit this page: // http://localhost:9000/?q="dog" - - diff --git a/48_passing-data/02_form-values/main.go b/48_passing-data/02_form-values/main.go index 7f508951..f20287cd 100644 --- a/48_passing-data/02_form-values/main.go +++ b/48_passing-data/02_form-values/main.go @@ -1,9 +1,9 @@ package main import ( - "net/http" - "io" "fmt" + "io" + "net/http" ) func main() { @@ -21,5 +21,3 @@ func main() { }) http.ListenAndServe(":9000", nil) } - - diff --git a/48_passing-data/03_form-values/main.go b/48_passing-data/03_form-values/main.go index 6a43f3dc..122f2f52 100644 --- a/48_passing-data/03_form-values/main.go +++ b/48_passing-data/03_form-values/main.go @@ -1,9 +1,9 @@ package main import ( - "net/http" - "io" "fmt" + "io" + "net/http" ) func main() { @@ -17,9 +17,7 @@ func main() { - ` + val) + `+val) }) http.ListenAndServe(":9000", nil) } - - diff --git a/48_passing-data/04_form-values/main.go b/48_passing-data/04_form-values/main.go index d44360e3..90ca6d16 100644 --- a/48_passing-data/04_form-values/main.go +++ b/48_passing-data/04_form-values/main.go @@ -1,9 +1,9 @@ package main import ( - "net/http" - "io" "fmt" + "io" + "net/http" ) func main() { @@ -17,9 +17,7 @@ func main() { - ` + val) + `+val) }) http.ListenAndServe(":9000", nil) } - - diff --git a/48_passing-data/05_form-values/main.go b/48_passing-data/05_form-values/main.go index d64d7be5..45119fb9 100644 --- a/48_passing-data/05_form-values/main.go +++ b/48_passing-data/05_form-values/main.go @@ -1,9 +1,9 @@ package main import ( - "net/http" - "io" "fmt" + "io" + "net/http" ) func main() { @@ -20,4 +20,4 @@ func main() { `) }) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/48_passing-data/07_form-data/main.go b/48_passing-data/07_form-data/main.go index d6046984..c87eb229 100644 --- a/48_passing-data/07_form-data/main.go +++ b/48_passing-data/07_form-data/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "html/template" "log" "net/http" - "fmt" "reflect" ) diff --git a/48_passing-data/08_form_file-upload/03/main.go b/48_passing-data/08_form_file-upload/03/main.go index abffb783..f853e470 100644 --- a/48_passing-data/08_form_file-upload/03/main.go +++ b/48_passing-data/08_form_file-upload/03/main.go @@ -1,13 +1,13 @@ package main - import ( - "net/http" + "fmt" "io" + "net/http" "os" "path/filepath" - "fmt" ) + func main() { fmt.Println("TEMP DIR:", os.TempDir()) http.ListenAndServe(":9000", http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { @@ -38,5 +38,3 @@ func main() { `) })) } - - diff --git a/48_passing-data/08_form_file-upload/04/main.go b/48_passing-data/08_form_file-upload/04/main.go index 43e1b1e9..1639ecdc 100644 --- a/48_passing-data/08_form_file-upload/04/main.go +++ b/48_passing-data/08_form_file-upload/04/main.go @@ -1,12 +1,12 @@ package main - import ( - "net/http" "io" + "net/http" "os" "path/filepath" ) + func main() { http.ListenAndServe(":9000", http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { if req.Method == "POST" { @@ -38,5 +38,3 @@ func main() { `) })) } - - diff --git a/49_cookies-sessions/05_sessions-HMAC/02/main.go b/49_cookies-sessions/05_sessions-HMAC/02/main.go index da473e95..40b74840 100644 --- a/49_cookies-sessions/05_sessions-HMAC/02/main.go +++ b/49_cookies-sessions/05_sessions-HMAC/02/main.go @@ -55,5 +55,3 @@ func main() { }) http.ListenAndServe(":9000", nil) } - - diff --git a/49_cookies-sessions/09_HTTPS-TLS/main.go b/49_cookies-sessions/09_HTTPS-TLS/main.go index 3abfbf45..66b5c53c 100644 --- a/49_cookies-sessions/09_HTTPS-TLS/main.go +++ b/49_cookies-sessions/09_HTTPS-TLS/main.go @@ -20,4 +20,4 @@ func main() { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/49_cookies-sessions/10_HTTPS-TLS/main.go b/49_cookies-sessions/10_HTTPS-TLS/main.go index d805c498..64574f48 100644 --- a/49_cookies-sessions/10_HTTPS-TLS/main.go +++ b/49_cookies-sessions/10_HTTPS-TLS/main.go @@ -14,10 +14,10 @@ func main() { http.HandleFunc("/", handler) log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/") - go http.ListenAndServe(":9999", http.RedirectHandler("https://127.0.0.1:10443/",301)) + go http.ListenAndServe(":9999", http.RedirectHandler("https://127.0.0.1:10443/", 301)) err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil) if err != nil { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/49_cookies-sessions/11_HTTPS-TLS/main.go b/49_cookies-sessions/11_HTTPS-TLS/main.go index 802b7eb2..77c18bb2 100644 --- a/49_cookies-sessions/11_HTTPS-TLS/main.go +++ b/49_cookies-sessions/11_HTTPS-TLS/main.go @@ -24,4 +24,4 @@ func main() { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/49_cookies-sessions/12_GORILLA_photo-blog/main.go b/49_cookies-sessions/12_GORILLA_photo-blog/main.go index e0644e85..d38dc06a 100644 --- a/49_cookies-sessions/12_GORILLA_photo-blog/main.go +++ b/49_cookies-sessions/12_GORILLA_photo-blog/main.go @@ -4,6 +4,7 @@ import ( "crypto/sha1" "encoding/json" "fmt" + "github.com/gorilla/context" "github.com/gorilla/sessions" "html/template" "io" @@ -11,7 +12,6 @@ import ( "net/http" "os" "path/filepath" - "github.com/gorilla/context" ) var tpl *template.Template diff --git a/50_exif/main.go b/50_exif/main.go index baa67900..3d92702d 100644 --- a/50_exif/main.go +++ b/50_exif/main.go @@ -1,11 +1,11 @@ package main import ( - "os" - "log" + "fmt" "github.com/rwcarlsen/goexif/exif" "github.com/rwcarlsen/goexif/mknote" - "fmt" + "log" + "os" ) func main() { diff --git a/51_appengine-introduction/01_hello-world/hello.go b/51_appengine-introduction/01_hello-world/hello.go index c3a51b40..267768b7 100644 --- a/51_appengine-introduction/01_hello-world/hello.go +++ b/51_appengine-introduction/01_hello-world/hello.go @@ -11,4 +11,4 @@ func init() { func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello, worlddddddddxxxxxx!") -} \ No newline at end of file +} diff --git a/51_appengine-introduction/02_photo-blog_somewhat-crappy-code-FYI/photos.go b/51_appengine-introduction/02_photo-blog_somewhat-crappy-code-FYI/photos.go index f6b29cc1..1fe160ec 100644 --- a/51_appengine-introduction/02_photo-blog_somewhat-crappy-code-FYI/photos.go +++ b/51_appengine-introduction/02_photo-blog_somewhat-crappy-code-FYI/photos.go @@ -1,22 +1,21 @@ package photos import ( + "fmt" "github.com/gorilla/sessions" + "github.com/rwcarlsen/goexif/exif" + "github.com/rwcarlsen/goexif/mknote" "html/template" "io" "log" "net/http" "os" "path/filepath" - "github.com/rwcarlsen/goexif/exif" - "github.com/rwcarlsen/goexif/mknote" - "fmt" ) var tpl *template.Template var store = sessions.NewCookieStore([]byte("something-very-secret")) - func init() { var err error tpl, err = template.ParseFiles("assets/tpl/index.gohtml", "assets/tpl/admin_login.gohtml", "assets/tpl/admin_upload.gohtml") @@ -35,12 +34,12 @@ func home(res http.ResponseWriter, req *http.Request) { type Photo struct { PhotoPath string - Lat float64 - Long float64 + Lat float64 + Long float64 } var model struct { - Photos []Photo + Photos []Photo LoggedIn bool } @@ -69,8 +68,8 @@ func home(res http.ResponseWriter, req *http.Request) { return nil } - currentPhoto.Lat , currentPhoto.Long, _ = x.LatLong() - fmt.Println("lat, long: ", currentPhoto.Lat , ", ", currentPhoto.Long) + currentPhoto.Lat, currentPhoto.Long, _ = x.LatLong() + fmt.Println("lat, long: ", currentPhoto.Lat, ", ", currentPhoto.Long) model.Photos = append(model.Photos, currentPhoto) } @@ -132,4 +131,4 @@ func logout(res http.ResponseWriter, req *http.Request) { session.Save(req, res) http.Redirect(res, req, "/admin", 302) return -} \ No newline at end of file +} diff --git a/51_appengine-introduction/03_google-maps-api/hello.go b/51_appengine-introduction/03_google-maps-api/hello.go index aa04e024..7b89defd 100755 --- a/51_appengine-introduction/03_google-maps-api/hello.go +++ b/51_appengine-introduction/03_google-maps-api/hello.go @@ -1,11 +1,11 @@ package main import ( + "github.com/rwcarlsen/goexif/exif" + "html/template" "log" "net/http" "os" - "github.com/rwcarlsen/goexif/exif" - "html/template" ) const GoogleAPIKey = "AIzaSyDpMNCWNz2UENVGQOS6zMFvtLsXn0zMBf4" diff --git a/51_appengine-introduction/05_GORILLA_photo-blog/main.go b/51_appengine-introduction/05_GORILLA_photo-blog/main.go index 7b183329..af0a49f6 100644 --- a/51_appengine-introduction/05_GORILLA_photo-blog/main.go +++ b/51_appengine-introduction/05_GORILLA_photo-blog/main.go @@ -4,6 +4,7 @@ import ( "crypto/sha1" "encoding/json" "fmt" + "github.com/gorilla/context" "github.com/gorilla/sessions" "html/template" "io" @@ -11,7 +12,6 @@ import ( "net/http" "os" "path/filepath" - "github.com/gorilla/context" ) var tpl *template.Template diff --git a/52_memcache/03_expiration/main.go b/52_memcache/03_expiration/main.go index 5b79f965..e5a86c9e 100755 --- a/52_memcache/03_expiration/main.go +++ b/52_memcache/03_expiration/main.go @@ -16,13 +16,13 @@ func init() { func handleIndex(res http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) -// item1 := memcache.Item{ -// Key: "foo", -// Value: []byte("bar"), -// Expiration: 10 * time.Second, -// } -// -// memcache.Set(ctx, &item1) + // item1 := memcache.Item{ + // Key: "foo", + // Value: []byte("bar"), + // Expiration: 10 * time.Second, + // } + // + // memcache.Set(ctx, &item1) item, _ := memcache.Get(ctx, "foo") if item != nil { diff --git a/52_memcache/05_memcache-session/02i/main.go b/52_memcache/05_memcache-session/02i/main.go index e5b687fc..489eec73 100755 --- a/52_memcache/05_memcache-session/02i/main.go +++ b/52_memcache/05_memcache-session/02i/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "net/http" "github.com/nu7hatch/gouuid" + "net/http" ) func init() { diff --git a/52_memcache/05_memcache-session/03i/main.go b/52_memcache/05_memcache-session/03i/main.go index 4fb6a0e3..98e214de 100755 --- a/52_memcache/05_memcache-session/03i/main.go +++ b/52_memcache/05_memcache-session/03i/main.go @@ -2,10 +2,10 @@ package main import ( "fmt" - "net/http" + "github.com/nu7hatch/gouuid" "google.golang.org/appengine" "google.golang.org/appengine/memcache" - "github.com/nu7hatch/gouuid" + "net/http" ) func init() { diff --git a/52_memcache/05_memcache-session/04i/main.go b/52_memcache/05_memcache-session/04i/main.go index 518e3788..5a058f58 100755 --- a/52_memcache/05_memcache-session/04i/main.go +++ b/52_memcache/05_memcache-session/04i/main.go @@ -3,10 +3,10 @@ package main import ( "encoding/json" "fmt" - "net/http" + "github.com/nu7hatch/gouuid" "google.golang.org/appengine" "google.golang.org/appengine/memcache" - "github.com/nu7hatch/gouuid" + "net/http" ) func init() { diff --git a/52_memcache/05_memcache-session/05i/main.go b/52_memcache/05_memcache-session/05i/main.go index 573cfd36..b020eb8f 100755 --- a/52_memcache/05_memcache-session/05i/main.go +++ b/52_memcache/05_memcache-session/05i/main.go @@ -3,10 +3,10 @@ package main import ( "encoding/json" "fmt" - "net/http" + "github.com/nu7hatch/gouuid" "google.golang.org/appengine" "google.golang.org/appengine/memcache" - "github.com/nu7hatch/gouuid" + "net/http" ) func init() { diff --git a/53_datastore/01_partial-example_does-not-run/main.go b/53_datastore/01_partial-example_does-not-run/main.go index 1c6976e2..f09b6099 100644 --- a/53_datastore/01_partial-example_does-not-run/main.go +++ b/53_datastore/01_partial-example_does-not-run/main.go @@ -17,7 +17,6 @@ type Employee struct { Account string } - func handle(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) @@ -41,4 +40,4 @@ func handle(w http.ResponseWriter, r *http.Request) { } fmt.Fprintf(w, "Stored and retrieved the Employee named %q", e2.Name) -} \ No newline at end of file +} diff --git a/53_datastore/02/05_query-ancestor/words.go b/53_datastore/02/05_query-ancestor/words.go index 3a494428..eb065d22 100755 --- a/53_datastore/02/05_query-ancestor/words.go +++ b/53_datastore/02/05_query-ancestor/words.go @@ -16,7 +16,7 @@ func init() { } type Animal struct { - Species string + Species string Description string } @@ -111,7 +111,7 @@ func showAnimal(res http.ResponseWriter, req *http.Request, term string) {

This Animal Just Ate:

- +

This Animal Has Already Eaten:

@@ -125,7 +125,7 @@ func saveAnimal(res http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) key := datastore.NewKey(ctx, "Animal", term, 0, nil) entity := Animal{ - Species: term, + Species: term, Description: definition, } @@ -138,7 +138,6 @@ func saveAnimal(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/", 302) } - func ateProcess(res http.ResponseWriter, req *http.Request) { fooditem := req.FormValue("fooditem") eater := req.FormValue("eater") diff --git a/53_datastore/04_julien-schmidt-router/01/main.go b/53_datastore/04_julien-schmidt-router/01/main.go index e5158fae..3dcd1974 100644 --- a/53_datastore/04_julien-schmidt-router/01/main.go +++ b/53_datastore/04_julien-schmidt-router/01/main.go @@ -21,4 +21,4 @@ func main() { router.GET("/hello/:name", Hello) log.Fatal(http.ListenAndServe(":8080", router)) -} \ No newline at end of file +} diff --git a/53_datastore/04_julien-schmidt-router/02-with-appengine/main.go b/53_datastore/04_julien-schmidt-router/02-with-appengine/main.go index 561e3eef..90d6b79f 100644 --- a/53_datastore/04_julien-schmidt-router/02-with-appengine/main.go +++ b/53_datastore/04_julien-schmidt-router/02-with-appengine/main.go @@ -19,4 +19,4 @@ func init() { router.GET("/", Index) router.GET("/hello/:name", Hello) http.Handle("/", router) -} \ No newline at end of file +} diff --git a/56_twitter/02_ListenAndServe/main.go b/56_twitter/02_ListenAndServe/main.go index 46f532c8..2fc75dc6 100644 --- a/56_twitter/02_ListenAndServe/main.go +++ b/56_twitter/02_ListenAndServe/main.go @@ -21,4 +21,4 @@ func home(res http.ResponseWriter, req *http.Request) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/03_error-handling/main.go b/56_twitter/03_error-handling/main.go index d9ceefaf..0a26f7bd 100644 --- a/56_twitter/03_error-handling/main.go +++ b/56_twitter/03_error-handling/main.go @@ -2,8 +2,8 @@ package main import ( "html/template" - "net/http" "log" + "net/http" ) var tpl *template.Template @@ -22,4 +22,4 @@ func home(res http.ResponseWriter, req *http.Request) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/04_template_abstraction/main.go b/56_twitter/04_template_abstraction/main.go index d9ceefaf..0a26f7bd 100644 --- a/56_twitter/04_template_abstraction/main.go +++ b/56_twitter/04_template_abstraction/main.go @@ -2,8 +2,8 @@ package main import ( "html/template" - "net/http" "log" + "net/http" ) var tpl *template.Template @@ -22,4 +22,4 @@ func home(res http.ResponseWriter, req *http.Request) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/05_document/main.go b/56_twitter/05_document/main.go index 06976a51..c3b7c340 100644 --- a/56_twitter/05_document/main.go +++ b/56_twitter/05_document/main.go @@ -22,8 +22,8 @@ package main import ( "html/template" - "net/http" "log" + "net/http" ) // tpl holds all of our templates. @@ -64,4 +64,4 @@ func GodocExperiment() { // documentation when godoc is run. func godocUnexported() { log.Println("This is a godoc UNEXPORTED experiment") -} \ No newline at end of file +} diff --git a/56_twitter/06_document/doc.go b/56_twitter/06_document/doc.go index 079394bb..989c311a 100644 --- a/56_twitter/06_document/doc.go +++ b/56_twitter/06_document/doc.go @@ -18,4 +18,4 @@ Try these godoc commands: godoc . godoc -http=:6060 */ -package main \ No newline at end of file +package main diff --git a/56_twitter/06_document/main.go b/56_twitter/06_document/main.go index d9ceefaf..0a26f7bd 100644 --- a/56_twitter/06_document/main.go +++ b/56_twitter/06_document/main.go @@ -2,8 +2,8 @@ package main import ( "html/template" - "net/http" "log" + "net/http" ) var tpl *template.Template @@ -22,4 +22,4 @@ func home(res http.ResponseWriter, req *http.Request) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/07_app-engine/doc.go b/56_twitter/07_app-engine/doc.go index 079394bb..989c311a 100644 --- a/56_twitter/07_app-engine/doc.go +++ b/56_twitter/07_app-engine/doc.go @@ -18,4 +18,4 @@ Try these godoc commands: godoc . godoc -http=:6060 */ -package main \ No newline at end of file +package main diff --git a/56_twitter/07_app-engine/main.go b/56_twitter/07_app-engine/main.go index 7c8bac0f..c6bde65f 100644 --- a/56_twitter/07_app-engine/main.go +++ b/56_twitter/07_app-engine/main.go @@ -22,4 +22,4 @@ func home(res http.ResponseWriter, req *http.Request) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/08_julien-schmidt/doc.go b/56_twitter/08_julien-schmidt/doc.go index 079394bb..989c311a 100644 --- a/56_twitter/08_julien-schmidt/doc.go +++ b/56_twitter/08_julien-schmidt/doc.go @@ -18,4 +18,4 @@ Try these godoc commands: godoc . godoc -http=:6060 */ -package main \ No newline at end of file +package main diff --git a/56_twitter/08_julien-schmidt/main.go b/56_twitter/08_julien-schmidt/main.go index 939d030a..1f014db3 100644 --- a/56_twitter/08_julien-schmidt/main.go +++ b/56_twitter/08_julien-schmidt/main.go @@ -1,9 +1,9 @@ package main import ( + "github.com/julienschmidt/httprouter" "html/template" "net/http" - "github.com/julienschmidt/httprouter" ) var tpl *template.Template @@ -23,4 +23,4 @@ func Home(res http.ResponseWriter, req *http.Request, _ httprouter.Params) { return } tpl.ExecuteTemplate(res, "home.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/09_login-form/doc.go b/56_twitter/09_login-form/doc.go index 079394bb..989c311a 100644 --- a/56_twitter/09_login-form/doc.go +++ b/56_twitter/09_login-form/doc.go @@ -18,4 +18,4 @@ Try these godoc commands: godoc . godoc -http=:6060 */ -package main \ No newline at end of file +package main diff --git a/56_twitter/09_login-form/main.go b/56_twitter/09_login-form/main.go index cce9147c..4f915b95 100644 --- a/56_twitter/09_login-form/main.go +++ b/56_twitter/09_login-form/main.go @@ -1,9 +1,9 @@ package main import ( + "github.com/julienschmidt/httprouter" "html/template" "net/http" - "github.com/julienschmidt/httprouter" ) var tpl *template.Template @@ -33,4 +33,4 @@ func Login(res http.ResponseWriter, req *http.Request, _ httprouter.Params) { func Signup(res http.ResponseWriter, req *http.Request, _ httprouter.Params) { tpl.ExecuteTemplate(res, "signup.html", nil) -} \ No newline at end of file +} diff --git a/56_twitter/10_signup-form-validate/01v_form-validation/main.go b/56_twitter/10_signup-form-validate/01v_form-validation/main.go index a76f1b23..6152608a 100644 --- a/56_twitter/10_signup-form-validate/01v_form-validation/main.go +++ b/56_twitter/10_signup-form-validate/01v_form-validation/main.go @@ -1,15 +1,15 @@ package main import ( + "fmt" "github.com/julienschmidt/httprouter" "google.golang.org/appengine" "google.golang.org/appengine/datastore" "html/template" - "net/http" - "log" - "fmt" "io/ioutil" + "log" stdlog "log" + "net/http" ) type User struct { @@ -76,4 +76,4 @@ func createUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) } log.Println(NewUser) fmt.Fprintln(res, NewUser.Email, NewUser.Password, NewUser.UserName) -} \ No newline at end of file +} diff --git a/56_twitter/10_signup-form-validate/02v_datastore-put/main.go b/56_twitter/10_signup-form-validate/02v_datastore-put/main.go index 1c620a90..d22ecec9 100644 --- a/56_twitter/10_signup-form-validate/02v_datastore-put/main.go +++ b/56_twitter/10_signup-form-validate/02v_datastore-put/main.go @@ -6,9 +6,9 @@ import ( "google.golang.org/appengine" "google.golang.org/appengine/datastore" "html/template" - "net/http" - stdlog "log" "io/ioutil" + stdlog "log" + "net/http" ) type User struct { diff --git a/56_twitter/11_HTTPS-TLS/main.go b/56_twitter/11_HTTPS-TLS/main.go index 5873f411..03530263 100644 --- a/56_twitter/11_HTTPS-TLS/main.go +++ b/56_twitter/11_HTTPS-TLS/main.go @@ -6,9 +6,9 @@ import ( "google.golang.org/appengine" "google.golang.org/appengine/datastore" "html/template" - "net/http" - stdlog "log" "io/ioutil" + stdlog "log" + "net/http" ) type User struct { @@ -86,4 +86,4 @@ https://cloud.google.com/appengine/docs/go/config/appconfig https://cloud.google.com/appengine/docs/using-custom-domains-and-ssl -*/ \ No newline at end of file +*/ diff --git a/56_twitter/12_error-handling/main.go b/56_twitter/12_error-handling/main.go index c5ffa89b..a75cc943 100644 --- a/56_twitter/12_error-handling/main.go +++ b/56_twitter/12_error-handling/main.go @@ -5,11 +5,11 @@ import ( "github.com/julienschmidt/httprouter" "google.golang.org/appengine" "google.golang.org/appengine/datastore" - "html/template" - "net/http" "google.golang.org/appengine/log" - stdlog "log" + "html/template" "io/ioutil" + stdlog "log" + "net/http" ) type User struct { @@ -84,4 +84,4 @@ func createUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) return } http.Redirect(res, req, "/", 302) -} \ No newline at end of file +} diff --git a/56_twitter/13_login_unfinished/main.go b/56_twitter/13_login_unfinished/main.go index c5ffa89b..a75cc943 100644 --- a/56_twitter/13_login_unfinished/main.go +++ b/56_twitter/13_login_unfinished/main.go @@ -5,11 +5,11 @@ import ( "github.com/julienschmidt/httprouter" "google.golang.org/appengine" "google.golang.org/appengine/datastore" - "html/template" - "net/http" "google.golang.org/appengine/log" - stdlog "log" + "html/template" "io/ioutil" + stdlog "log" + "net/http" ) type User struct { @@ -84,4 +84,4 @@ func createUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) return } http.Redirect(res, req, "/", 302) -} \ No newline at end of file +} diff --git a/56_twitter/14_code-review/main.go b/56_twitter/14_code-review/main.go index 2d031db2..6cb21981 100644 --- a/56_twitter/14_code-review/main.go +++ b/56_twitter/14_code-review/main.go @@ -5,13 +5,13 @@ import ( "github.com/julienschmidt/httprouter" "google.golang.org/appengine" "google.golang.org/appengine/datastore" - "html/template" - "net/http" "google.golang.org/appengine/log" + "html/template" "io/ioutil" -// "io" -// "bytes" -// "google.golang.org/appengine/memcache" + "net/http" + // "io" + // "bytes" + // "google.golang.org/appengine/memcache" ) type User struct { @@ -101,4 +101,4 @@ post tweets follow people see tweets for everyone see tweets for individual user -*/ \ No newline at end of file +*/ diff --git a/56_twitter/15_memcache-templates/main.go b/56_twitter/15_memcache-templates/main.go index 9aeab2c1..f5b24d61 100644 --- a/56_twitter/15_memcache-templates/main.go +++ b/56_twitter/15_memcache-templates/main.go @@ -5,13 +5,13 @@ import ( "github.com/julienschmidt/httprouter" "google.golang.org/appengine" "google.golang.org/appengine/datastore" - "html/template" - "net/http" "google.golang.org/appengine/log" + "html/template" "io/ioutil" -// "io" -// "bytes" -// "google.golang.org/appengine/memcache" + "net/http" + "io" + "bytes" + "google.golang.org/appengine/memcache" ) type User struct { @@ -36,20 +36,19 @@ func init() { } func Home(res http.ResponseWriter, req *http.Request, _ httprouter.Params) { -// ctx := appengine.NewContext(req) -// i, err := memcache.Get(ctx, "Homepage") -// if err == memcache.ErrCacheMiss { -// buf := bytes.NewBuffer(make([]byte)) -// writ := io.MultiWriter(res, buf) -// tpl.ExecuteTemplate(writ, "home.html", nil) -// memcache.Set(ctx, memcache.Item{ -// Value: buf.String(), -// Key: "Homepage", -// }) -// return -// } -// io.WriteString(res, i.Value) - tpl.ExecuteTemplate(res, "home.html", nil) + ctx := appengine.NewContext(req) + i, err := memcache.Get(ctx, "Homepage") + if err == memcache.ErrCacheMiss { + buf := bytes.NewBuffer(make([]byte)) + writ := io.MultiWriter(res, buf) + tpl.ExecuteTemplate(writ, "home.html", nil) + memcache.Set(ctx, memcache.Item{ + Value: buf.String(), + Key: "Homepage", + }) + return + } + io.WriteString(res, i.Value) } func Login(res http.ResponseWriter, req *http.Request, _ httprouter.Params) { @@ -98,8 +97,9 @@ func createUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) } /* -TODO: +TO DO: session +-memcache templates - uuid in a cookie --- https while logged in? - depends upon security required - encrypt password on datastore? @@ -108,18 +108,9 @@ session - user memcache? - datastore / memcache session interface change -- change login button to logout when user logged func init() { +- change login button to logout when user logged in post tweets follow people see tweets for everyone see tweets for individual user -} - - - - - - - - -*/ \ No newline at end of file +*/ diff --git a/56_twitter/xx_under-development/data.go b/56_twitter/xx_under-development/data.go index d1c6fb26..c60ad704 100644 --- a/56_twitter/xx_under-development/data.go +++ b/56_twitter/xx_under-development/data.go @@ -1,14 +1,14 @@ package main import ( - "google.golang.org/appengine/user" - "google.golang.org/appengine/datastore" - "google.golang.org/appengine" - "net/http" - "time" "fmt" "golang.org/x/net/context" + "google.golang.org/appengine" + "google.golang.org/appengine/datastore" "google.golang.org/appengine/log" + "google.golang.org/appengine/user" + "net/http" + "time" ) type Profile struct { @@ -17,8 +17,8 @@ type Profile struct { } type Tweet struct { - Message string - Time time.Time + Message string + Time time.Time Username string } @@ -35,6 +35,7 @@ func getProfileByUsername(ctx context.Context, username string) (*Profile, error } return &profiles[0], nil } + // get profile by email func getProfileByEmail(ctx context.Context, email string) (*Profile, error) { key := datastore.NewKey(ctx, "Profile", email, 0, nil) @@ -60,6 +61,7 @@ func createProfile(req *http.Request, profile *Profile) error { return err // you can use memcache also to improve your consistency } + // for eventual consistency thing // assumption: user will show up in 10 seconds on datastore func waitForProfile(req *http.Request, username string) error { @@ -75,7 +77,6 @@ func waitForProfile(req *http.Request, username string) error { return nil } - //// insert tweet func putTweet(ctx context.Context, tweet *Tweet, email string) error { userKey := datastore.NewKey(ctx, "Profile", email, 0, nil) @@ -86,6 +87,7 @@ func putTweet(ctx context.Context, tweet *Tweet, email string) error { } return nil } + // get user tweets func userTweets(ctx context.Context, email string) ([]Tweet, error) { var tweets []Tweet @@ -95,6 +97,7 @@ func userTweets(ctx context.Context, email string) ([]Tweet, error) { return tweets, err } + // get recent tweets func recentTweets(ctx context.Context) ([]Tweet, error) { var tweets []Tweet @@ -103,6 +106,7 @@ func recentTweets(ctx context.Context) ([]Tweet, error) { return tweets, err } + //// delete tweet //func delTweet(ctx context.Context, username string) (*Profile, error) { // @@ -115,7 +119,3 @@ func checkLoggedInStats(req *http.Request) bool { } return false } - - - - diff --git a/56_twitter/xx_under-development/routes.go b/56_twitter/xx_under-development/routes.go index 02a0b6a6..c80fd0ae 100644 --- a/56_twitter/xx_under-development/routes.go +++ b/56_twitter/xx_under-development/routes.go @@ -1,16 +1,16 @@ package main import ( + "encoding/json" + "github.com/dustin/go-humanize" + "golang.org/x/net/context" "google.golang.org/appengine" + "google.golang.org/appengine/log" + "google.golang.org/appengine/mail" "google.golang.org/appengine/user" "net/http" "strings" - "google.golang.org/appengine/log" - "encoding/json" - "golang.org/x/net/context" "time" - "google.golang.org/appengine/mail" - "github.com/dustin/go-humanize" ) func init() { @@ -34,8 +34,8 @@ func home(res http.ResponseWriter, req *http.Request) { log.Infof(ctx, "user: ", u) // pointers can be NIL so don't use a Profile * Profile here: var model struct { - Profile Profile - Tweets []Tweet + Profile Profile + Tweets []Tweet LoggedIn bool } @@ -44,7 +44,7 @@ func home(res http.ResponseWriter, req *http.Request) { if u != nil { profile, err := getProfileByEmail(ctx, u.Email) if err != nil { - http.Redirect(res, req, "/login", 302) + http.Redirect(res, req, "/login", 302) return } model.Profile = *profile @@ -58,8 +58,7 @@ func home(res http.ResponseWriter, req *http.Request) { } model.Tweets = tweets - - renderTemplate(res, "home.html", model) + renderTemplate(res, "home.html", model) } func login(res http.ResponseWriter, req *http.Request) { @@ -75,8 +74,8 @@ func login(res http.ResponseWriter, req *http.Request) { } var model struct { - Profile *Profile - Error string + Profile *Profile + Error string LoggedIn bool } @@ -131,8 +130,8 @@ func profile(res http.ResponseWriter, req *http.Request) { // Render the template var model struct { - Profile *Profile - Tweets []Tweet + Profile *Profile + Tweets []Tweet LoggedIn bool } model.LoggedIn = checkLoggedInStats(req) @@ -142,13 +141,13 @@ func profile(res http.ResponseWriter, req *http.Request) { renderTemplate(res, "profile.html", model) /* - // Render the template - type Model struct { - Profile *Profile - } - renderTemplate(res, "user-profile", Model{ - Profile: profile, - }) + // Render the template + type Model struct { + Profile *Profile + } + renderTemplate(res, "user-profile", Model{ + Profile: profile, + }) */ } @@ -157,7 +156,7 @@ func handleTweet(res http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) u := user.Current(ctx) var tweet *Tweet - tweet = decodeTweet(ctx, res, req); + tweet = decodeTweet(ctx, res, req) tweet.Time = time.Now() // add in username var profile *Profile @@ -187,7 +186,7 @@ func decodeTweet(ctx context.Context, res http.ResponseWriter, req *http.Request func logout(res http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) - http.SetCookie(res, &http.Cookie{Name: "logged_in", Value: "", MaxAge:-1}) + http.SetCookie(res, &http.Cookie{Name: "logged_in", Value: "", MaxAge: -1}) url, err := user.LogoutURL(ctx, "/") if err != nil { http.Error(res, err.Error(), 500) @@ -210,7 +209,7 @@ func emailMentions(ctx context.Context, tweet *Tweet) { } msg := &mail.Message{ Sender: u.Email, - To: []string{profile.Username + " <" + profile.Email +">"}, + To: []string{profile.Username + " <" + profile.Email + ">"}, Subject: "You were mentioned in a tweet", Body: tweet.Message + " from " + tweet.Username + " - " + humanize.Time(tweet.Time), } @@ -221,4 +220,4 @@ func emailMentions(ctx context.Context, tweet *Tweet) { } } -} \ No newline at end of file +} diff --git a/56_twitter/xx_under-development/templates.go b/56_twitter/xx_under-development/templates.go index 1e728d42..2552f044 100644 --- a/56_twitter/xx_under-development/templates.go +++ b/56_twitter/xx_under-development/templates.go @@ -1,9 +1,9 @@ package main import ( + "github.com/dustin/go-humanize" "html/template" "net/http" - "github.com/dustin/go-humanize" ) var tpl *template.Template @@ -23,8 +23,7 @@ func renderTemplate(res http.ResponseWriter, name string, data interface{}) { } } - // up above, you could have done it this way: // "humanize_time": func(tm time.Time) string { // return humanize.Time(tm) -// }, \ No newline at end of file +// }, diff --git a/56_twitter/zz_twitter_show-tweets/data.go b/56_twitter/zz_twitter_show-tweets/data.go index 7823c0f9..3f73c3fd 100644 --- a/56_twitter/zz_twitter_show-tweets/data.go +++ b/56_twitter/zz_twitter_show-tweets/data.go @@ -1,13 +1,13 @@ package main import ( - "google.golang.org/appengine/user" - "google.golang.org/appengine/datastore" + "fmt" + "golang.org/x/net/context" "google.golang.org/appengine" + "google.golang.org/appengine/datastore" + "google.golang.org/appengine/user" "net/http" "time" - "fmt" - "golang.org/x/net/context" ) type Profile struct { @@ -16,8 +16,8 @@ type Profile struct { } type Tweet struct { - Message string - Time time.Time + Message string + Time time.Time Username string } @@ -35,6 +35,7 @@ func getProfileByUsername(req *http.Request, username string) (*Profile, error) } return &profiles[0], nil } + // get profile by email func getProfileByEmail(ctx context.Context, email string) (*Profile, error) { key := datastore.NewKey(ctx, "Profile", email, 0, nil) @@ -60,6 +61,7 @@ func createProfile(req *http.Request, profile *Profile) error { return err // you can use memcache also to improve your consistency } + // for eventual consistency thing // assumption: user will show up in 10 seconds on datastore func waitForProfile(req *http.Request, username string) error { @@ -74,7 +76,6 @@ func waitForProfile(req *http.Request, username string) error { return nil } - //// insert tweet func putTweet(ctx context.Context, tweet *Tweet, email string) error { userKey := datastore.NewKey(ctx, "Profile", email, 0, nil) @@ -85,6 +86,7 @@ func putTweet(ctx context.Context, tweet *Tweet, email string) error { } return nil } + // get user tweets func userTweets(ctx context.Context, email string) ([]Tweet, error) { var tweets []Tweet @@ -94,6 +96,7 @@ func userTweets(ctx context.Context, email string) ([]Tweet, error) { return tweets, err } + // get recent tweets func recentTweets(ctx context.Context) ([]Tweet, error) { var tweets []Tweet @@ -102,9 +105,8 @@ func recentTweets(ctx context.Context) ([]Tweet, error) { return tweets, err } + //// delete tweet //func delTweet(ctx context.Context, username string) (*Profile, error) { // //} - - diff --git a/56_twitter/zz_twitter_show-tweets/routes.go b/56_twitter/zz_twitter_show-tweets/routes.go index 48328270..2cf79346 100644 --- a/56_twitter/zz_twitter_show-tweets/routes.go +++ b/56_twitter/zz_twitter_show-tweets/routes.go @@ -1,13 +1,13 @@ package main import ( + "encoding/json" + "golang.org/x/net/context" "google.golang.org/appengine" + "google.golang.org/appengine/log" "google.golang.org/appengine/user" "net/http" "strings" - "google.golang.org/appengine/log" - "encoding/json" - "golang.org/x/net/context" "time" ) @@ -33,13 +33,13 @@ func home(res http.ResponseWriter, req *http.Request) { // pointers can be NIL so don't use a Profile * Profile here: var model struct { Profile Profile - Tweets []Tweet + Tweets []Tweet } if u != nil { profile, err := getProfileByEmail(ctx, u.Email) if err != nil { - http.Redirect(res, req, "/login", 302) + http.Redirect(res, req, "/login", 302) return } model.Profile = *profile @@ -53,8 +53,7 @@ func home(res http.ResponseWriter, req *http.Request) { } model.Tweets = tweets - - renderTemplate(res, "home.html", model) + renderTemplate(res, "home.html", model) } func login(res http.ResponseWriter, req *http.Request) { @@ -124,7 +123,7 @@ func profile(res http.ResponseWriter, req *http.Request) { // Render the template var model struct { Profile *Profile - Tweets []Tweet + Tweets []Tweet } model.Profile = profile @@ -133,13 +132,13 @@ func profile(res http.ResponseWriter, req *http.Request) { renderTemplate(res, "profile.html", model) /* - // Render the template - type Model struct { - Profile *Profile - } - renderTemplate(res, "user-profile", Model{ - Profile: profile, - }) + // Render the template + type Model struct { + Profile *Profile + } + renderTemplate(res, "user-profile", Model{ + Profile: profile, + }) */ } @@ -148,7 +147,7 @@ func tweet(res http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) u := user.Current(ctx) var tweet *Tweet - tweet = receiveTweet(ctx, res, req); + tweet = receiveTweet(ctx, res, req) tweet.Time = time.Now() // add in username var profile *Profile @@ -176,4 +175,4 @@ func receiveTweet(ctx context.Context, res http.ResponseWriter, req *http.Reques func logout(res http.ResponseWriter, req *http.Request) { http.SetCookie(res, &http.Cookie{Name: "logged_in", Value: ""}) http.Redirect(res, req, "/", 302) -} \ No newline at end of file +} diff --git a/56_twitter/zz_twitter_show-tweets/templates.go b/56_twitter/zz_twitter_show-tweets/templates.go index 066c3dbe..8b79564d 100644 --- a/56_twitter/zz_twitter_show-tweets/templates.go +++ b/56_twitter/zz_twitter_show-tweets/templates.go @@ -16,4 +16,4 @@ func renderTemplate(res http.ResponseWriter, name string, data interface{}) { if err != nil { http.Error(res, err.Error(), 500) } -} \ No newline at end of file +} diff --git a/98_in-progress/40_photo-blog_step-01/main.go b/98_in-progress/40_photo-blog_step-01/main.go index c4c6f7f6..2dae87f3 100644 --- a/98_in-progress/40_photo-blog_step-01/main.go +++ b/98_in-progress/40_photo-blog_step-01/main.go @@ -1,20 +1,20 @@ package main import ( + "encoding/gob" + "encoding/json" + "github.com/gorilla/context" + "github.com/gorilla/sessions" "html/template" "io" "net/http" "os" "path/filepath" "strings" - "github.com/gorilla/sessions" - "github.com/gorilla/context" - "encoding/gob" - "encoding/json" ) type Model struct { - Photos []string + Photos []string loggedin bool } @@ -74,7 +74,7 @@ func upload(res http.ResponseWriter, req *http.Request) { defer dst.Close() io.Copy(dst, src) - state.Photos = append(state.Photos, "imgs/" + fileName) + state.Photos = append(state.Photos, "imgs/"+fileName) http.Redirect(res, req, "/", 302) return } @@ -84,4 +84,4 @@ func upload(res http.ResponseWriter, req *http.Request) { func logout(res http.ResponseWriter, req *http.Request) { state.loggedin = false http.Redirect(res, req, "/", 302) -} \ No newline at end of file +} diff --git a/98_in-progress/42_photo-blog/main.go b/98_in-progress/42_photo-blog/main.go index 2d580f3f..337df078 100644 --- a/98_in-progress/42_photo-blog/main.go +++ b/98_in-progress/42_photo-blog/main.go @@ -1,12 +1,12 @@ package main import ( - "net/http" "github.com/gorilla/sessions" "html/template" + "io" "log" + "net/http" "os" - "io" "path/filepath" "strings" ) @@ -16,7 +16,7 @@ var tpl *template.Template var store = sessions.NewCookieStore([]byte("something-very-secret")) type Model struct { - Pictures []string + Pictures []string } // []string of picture paths @@ -36,7 +36,6 @@ func main() { http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets")))) http.Handle("/favicon.ico", http.NotFoundHandler()) - // to generate cert and key: // go run $(go env GOROOT)/src/crypto/tls/generate_cert.go --host=localhost http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil) @@ -57,13 +56,13 @@ func login(res http.ResponseWriter, req *http.Request) { } else { http.Error(res, "invalid credentials", 401) return - } + } // save session session.Save(req, res) // redirect to main page http.Redirect(res, req, "/", 302) return - } + } // Execute template tpl.ExecuteTemplate(res, "login.gohtml", nil) } @@ -128,4 +127,4 @@ func getPicturePaths() Model { return nil }) return Model{Pictures: files} -} \ No newline at end of file +} diff --git a/99_svcc/01_string-to-html/main.go b/99_svcc/01_string-to-html/main.go index 5c3f9c8d..7c3846a3 100644 --- a/99_svcc/01_string-to-html/main.go +++ b/99_svcc/01_string-to-html/main.go @@ -13,8 +13,8 @@ func main() {

` + - name + - `

+ name + + ` `) diff --git a/99_svcc/02_os-args/main.go b/99_svcc/02_os-args/main.go index ea69488f..1ddecec3 100644 --- a/99_svcc/02_os-args/main.go +++ b/99_svcc/02_os-args/main.go @@ -18,8 +18,8 @@ func main() {

` + - name + - `

+ name + + ` `) diff --git a/99_svcc/03_text-template/main.go b/99_svcc/03_text-template/main.go index 6aac9958..6e025864 100644 --- a/99_svcc/03_text-template/main.go +++ b/99_svcc/03_text-template/main.go @@ -20,4 +20,4 @@ func main() { /* ParseFiles || ParseGlob Execute || ExecuteTemplate -*/ \ No newline at end of file +*/ diff --git a/99_svcc/07_composition/main.go b/99_svcc/07_composition/main.go index ccbbfb85..f8b47d6e 100644 --- a/99_svcc/07_composition/main.go +++ b/99_svcc/07_composition/main.go @@ -14,7 +14,7 @@ type Person struct { func main() { p1 := Person{ Name: "James Bond", - Age: 23, + Age: 23, } tpl, err := template.ParseFiles("tpl.gohtml") diff --git a/99_svcc/09_methods/main.go b/99_svcc/09_methods/main.go index 2910f450..e0c2ff0e 100644 --- a/99_svcc/09_methods/main.go +++ b/99_svcc/09_methods/main.go @@ -24,8 +24,8 @@ func (dz DoubleZero) Greeting() { func main() { p1 := Person{ - Name: "Ian Flemming", - Age: 44, + Name: "Ian Flemming", + Age: 44, } p2 := DoubleZero{ @@ -45,4 +45,4 @@ func main() { fmt.Println(p2.Name) fmt.Println(p2.Person.Name) -*/ \ No newline at end of file +*/ diff --git a/99_svcc/11_html-templates/main.go b/99_svcc/11_html-templates/main.go index bb0f28c0..cf78fd19 100644 --- a/99_svcc/11_html-templates/main.go +++ b/99_svcc/11_html-templates/main.go @@ -1,9 +1,9 @@ package main import ( + "html/template" "log" "os" - "html/template" ) type Page struct { diff --git a/99_svcc/12_parsefiles/main.go b/99_svcc/12_parsefiles/main.go index 01bcf558..13a254c8 100644 --- a/99_svcc/12_parsefiles/main.go +++ b/99_svcc/12_parsefiles/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "html/template" "log" "os" - "fmt" ) type Page struct { diff --git a/99_svcc/13_ParseGlob/main.go b/99_svcc/13_ParseGlob/main.go index 516e4456..7cf58acf 100644 --- a/99_svcc/13_ParseGlob/main.go +++ b/99_svcc/13_ParseGlob/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "html/template" "log" "os" - "fmt" ) type Page struct { diff --git a/99_svcc/14_tcp_echo-server/main.go b/99_svcc/14_tcp_echo-server/main.go index 553b27f1..96732fe7 100644 --- a/99_svcc/14_tcp_echo-server/main.go +++ b/99_svcc/14_tcp_echo-server/main.go @@ -27,4 +27,4 @@ func main() { /* start main.go (go run main.go) then ... telnet localhost 9000 -*/ \ No newline at end of file +*/ diff --git a/99_svcc/15_tcp_echo-server/main.go b/99_svcc/15_tcp_echo-server/main.go index 81d691b2..d4111c8b 100644 --- a/99_svcc/15_tcp_echo-server/main.go +++ b/99_svcc/15_tcp_echo-server/main.go @@ -1,10 +1,10 @@ package main import ( - "net" - "log" "bufio" "fmt" + "log" + "net" ) func handle(conn net.Conn) { @@ -20,7 +20,7 @@ func handle(conn net.Conn) { // as a newly allocated string holding its bytes. ln := scanner.Text() fmt.Println(ln) - fmt.Printf("TYPE: %T\n",ln) + fmt.Printf("TYPE: %T\n", ln) ln = fmt.Sprint("FROM SERVER: " + ln) fmt.Fprintln(conn, ln) } @@ -28,7 +28,7 @@ func handle(conn net.Conn) { func main() { li, err := net.Listen("tcp", ":9000") - if err != nil{ + if err != nil { log.Fatalln(err) } defer li.Close() @@ -45,4 +45,4 @@ func main() { /* start main.go (go run main.go) then ... telnet localhost 9000 -*/ \ No newline at end of file +*/ diff --git a/99_svcc/16_redis-clone_step-2/main.go b/99_svcc/16_redis-clone_step-2/main.go index f561846d..8d91b159 100644 --- a/99_svcc/16_redis-clone_step-2/main.go +++ b/99_svcc/16_redis-clone_step-2/main.go @@ -1,12 +1,12 @@ package main import ( - "net" - "log" "bufio" "fmt" - "strings" "io" + "log" + "net" + "strings" ) func handle(conn net.Conn) { @@ -44,7 +44,7 @@ func handle(conn net.Conn) { func main() { li, err := net.Listen("tcp", ":9000") - if err != nil{ + if err != nil { log.Fatalln(err) } defer li.Close() @@ -61,4 +61,4 @@ func main() { /* start main.go (go run main.go) then ... telnet localhost 9000 -*/ \ No newline at end of file +*/ diff --git a/99_svcc/17_redis-clone_step-5/main.go b/99_svcc/17_redis-clone_step-5/main.go index cbf52f8a..1cf63533 100644 --- a/99_svcc/17_redis-clone_step-5/main.go +++ b/99_svcc/17_redis-clone_step-5/main.go @@ -2,11 +2,11 @@ package main import ( "bufio" + "fmt" "io" "log" "net" "strings" - "fmt" ) var data = make(map[string]string) @@ -52,7 +52,7 @@ func handle(conn net.Conn) { default: fmt.Println(ln) ln = fmt.Sprint("FROM SERVER - USAGE [VAL]\n" + - "INVALID COMMAND: "+fs[0]+"\n\n") + "INVALID COMMAND: " + fs[0] + "\n\n") io.WriteString(conn, ln) } } diff --git a/99_svcc/19_DIY_http-server_request-line_headers/main.go b/99_svcc/19_DIY_http-server_request-line_headers/main.go index 10aa7eb6..93a40a61 100644 --- a/99_svcc/19_DIY_http-server_request-line_headers/main.go +++ b/99_svcc/19_DIY_http-server_request-line_headers/main.go @@ -38,5 +38,3 @@ go to your browser and go to localhost:9000 in the terminal on the server go look at the request line & request headers */ - - diff --git a/99_svcc/22_DIY_http-server_step-03/main.go b/99_svcc/22_DIY_http-server_step-03/main.go index 61e2873b..a2c29254 100644 --- a/99_svcc/22_DIY_http-server_step-03/main.go +++ b/99_svcc/22_DIY_http-server_step-03/main.go @@ -66,4 +66,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/99_svcc/23_DIY_http-server_step-04/main.go b/99_svcc/23_DIY_http-server_step-04/main.go index 40346036..5c97e6c8 100644 --- a/99_svcc/23_DIY_http-server_step-04/main.go +++ b/99_svcc/23_DIY_http-server_step-04/main.go @@ -66,4 +66,4 @@ func main() { } go handleConn(conn) } -} \ No newline at end of file +} diff --git a/99_svcc/24_http-server_ServeMux/main.go b/99_svcc/24_http-server_ServeMux/main.go index 855eeb29..76a49d73 100644 --- a/99_svcc/24_http-server_ServeMux/main.go +++ b/99_svcc/24_http-server_ServeMux/main.go @@ -5,7 +5,6 @@ import ( "net/http" ) - func upTown(res http.ResponseWriter, req *http.Request) { io.WriteString(res, "doggy doggy doggy") } @@ -21,4 +20,4 @@ func main() { mux.HandleFunc("/cat/", youUp) http.ListenAndServe(":9000", mux) -} \ No newline at end of file +} diff --git a/99_svcc/25_http-server_DefaultServeMux/main.go b/99_svcc/25_http-server_DefaultServeMux/main.go index 431f0f78..f243e72b 100644 --- a/99_svcc/25_http-server_DefaultServeMux/main.go +++ b/99_svcc/25_http-server_DefaultServeMux/main.go @@ -5,7 +5,6 @@ import ( "net/http" ) - func upTown(res http.ResponseWriter, req *http.Request) { io.WriteString(res, "doggy doggy doggy") } @@ -20,4 +19,4 @@ func main() { http.HandleFunc("/cat/", youUp) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/26_serving-files_io-Copy/main.go b/99_svcc/26_serving-files_io-Copy/main.go index cb25ff3e..2c9f3228 100644 --- a/99_svcc/26_serving-files_io-Copy/main.go +++ b/99_svcc/26_serving-files_io-Copy/main.go @@ -3,8 +3,8 @@ package main import ( "io" "net/http" - "strings" "os" + "strings" ) func upTown(res http.ResponseWriter, req *http.Request) { @@ -36,4 +36,4 @@ func main() { http.HandleFunc("/", upTown) http.HandleFunc("/toby.jpg", dogPic) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/27_serving-files_ServeContent/main.go b/99_svcc/27_serving-files_ServeContent/main.go index eca35a7c..9f86bddf 100644 --- a/99_svcc/27_serving-files_ServeContent/main.go +++ b/99_svcc/27_serving-files_ServeContent/main.go @@ -3,8 +3,8 @@ package main import ( "io" "net/http" - "strings" "os" + "strings" ) func upTown(res http.ResponseWriter, req *http.Request) { @@ -42,4 +42,4 @@ func main() { http.HandleFunc("/", upTown) http.HandleFunc("/toby.jpg", dogPic) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/28_serving-files_ServeFile/main.go b/99_svcc/28_serving-files_ServeFile/main.go index 6717a63e..2c89fc71 100644 --- a/99_svcc/28_serving-files_ServeFile/main.go +++ b/99_svcc/28_serving-files_ServeFile/main.go @@ -28,4 +28,4 @@ func main() { http.HandleFunc("/", upTown) http.HandleFunc("/toby.jpg", dogPic) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/29_serving-files_FileServer/main.go b/99_svcc/29_serving-files_FileServer/main.go index 1c4f783c..baeafd6a 100644 --- a/99_svcc/29_serving-files_FileServer/main.go +++ b/99_svcc/29_serving-files_FileServer/main.go @@ -26,4 +26,4 @@ func main() { http.Handle("/", http.FileServer(http.Dir("."))) http.HandleFunc("/dog/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/30_serving-files_FileServer/main.go b/99_svcc/30_serving-files_FileServer/main.go index 2b64361b..5bcfa2d0 100644 --- a/99_svcc/30_serving-files_FileServer/main.go +++ b/99_svcc/30_serving-files_FileServer/main.go @@ -24,4 +24,4 @@ func main() { http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets")))) http.HandleFunc("/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/31_serving-files_FileServer/main.go b/99_svcc/31_serving-files_FileServer/main.go index 99d884ac..fd0c0983 100644 --- a/99_svcc/31_serving-files_FileServer/main.go +++ b/99_svcc/31_serving-files_FileServer/main.go @@ -24,4 +24,4 @@ func main() { http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets")))) http.HandleFunc("/", upTown) http.ListenAndServe(":9000", nil) -} \ No newline at end of file +} diff --git a/99_svcc/38_HMAC/01/main.go b/99_svcc/38_HMAC/01/main.go index 325301d7..338c8e30 100644 --- a/99_svcc/38_HMAC/01/main.go +++ b/99_svcc/38_HMAC/01/main.go @@ -25,4 +25,4 @@ func getCode(data string) string { h := hmac.New(sha256.New, []byte("this can be anything we want it to be it is our private key")) io.WriteString(h, data) return fmt.Sprintf("%x", h.Sum(nil)) -} \ No newline at end of file +} diff --git a/99_svcc/38_HMAC/02/main.go b/99_svcc/38_HMAC/02/main.go index 47f522df..6fc2344e 100644 --- a/99_svcc/38_HMAC/02/main.go +++ b/99_svcc/38_HMAC/02/main.go @@ -4,8 +4,8 @@ import ( "crypto/hmac" "crypto/sha256" "fmt" - "io" "github.com/nu7hatch/gouuid" + "io" ) func main() { @@ -26,4 +26,4 @@ func getCode(data string) string { h := hmac.New(sha256.New, []byte("this can be anything we want it to be it is our private key")) io.WriteString(h, data) return fmt.Sprintf("%x", h.Sum(nil)) -} \ No newline at end of file +} diff --git a/99_svcc/38_HMAC/03/main.go b/99_svcc/38_HMAC/03/main.go index 9074b87b..1d7ceabd 100644 --- a/99_svcc/38_HMAC/03/main.go +++ b/99_svcc/38_HMAC/03/main.go @@ -4,9 +4,9 @@ import ( "crypto/hmac" "crypto/sha256" "fmt" + "github.com/nu7hatch/gouuid" "io" "net/http" - "github.com/nu7hatch/gouuid" "strings" ) @@ -21,9 +21,9 @@ func home(res http.ResponseWriter, req *http.Request) { if err != nil { id, _ := uuid.NewV4() code := getCode(id.String()) - val := code+"|"+id.String() + val := code + "|" + id.String() cookie = &http.Cookie{ - Name: "session-id", + Name: "session-id", Value: val, } } @@ -37,8 +37,8 @@ func home(res http.ResponseWriter, req *http.Request) { if code != cookieCode { fmt.Fprintln(res, "Cookie monsters says: someone's had their hands in my cookies!") cookie = &http.Cookie{ - Name: "session-id", - Value: "0", + Name: "session-id", + Value: "0", MaxAge: -1, } } @@ -50,4 +50,4 @@ func getCode(data string) string { h := hmac.New(sha256.New, []byte("ourkey")) io.WriteString(h, data) return fmt.Sprintf("%x", h.Sum(nil)) -} \ No newline at end of file +} diff --git a/99_svcc/40_sessions_GORILLA/main.go b/99_svcc/40_sessions_GORILLA/main.go index 78f3dde2..63f5df48 100644 --- a/99_svcc/40_sessions_GORILLA/main.go +++ b/99_svcc/40_sessions_GORILLA/main.go @@ -1,11 +1,11 @@ package main import ( + "fmt" + "github.com/gorilla/context" "github.com/gorilla/sessions" "io" "net/http" - "fmt" - "github.com/gorilla/context" ) var store = sessions.NewCookieStore([]byte("secret-password")) diff --git a/99_svcc/41_sessions_GORILLA_log-in-out/main.go b/99_svcc/41_sessions_GORILLA_log-in-out/main.go index 45ba2d5c..7c67c9e9 100644 --- a/99_svcc/41_sessions_GORILLA_log-in-out/main.go +++ b/99_svcc/41_sessions_GORILLA_log-in-out/main.go @@ -1,10 +1,10 @@ package main import ( + "github.com/gorilla/context" "github.com/gorilla/sessions" "io" "net/http" - "github.com/gorilla/context" ) var store = sessions.NewCookieStore([]byte("secret-password")) @@ -30,7 +30,7 @@ func authenticate(res http.ResponseWriter, req *http.Request) { // not logged in if session.Values["loggedin"] == "false" || - session.Values["loggedin"] == nil { + session.Values["loggedin"] == nil { html = ` diff --git a/99_svcc/43_sessions_GORILLA_JSON/main.go b/99_svcc/43_sessions_GORILLA_JSON/main.go index 19dc3502..5d362cfb 100644 --- a/99_svcc/43_sessions_GORILLA_JSON/main.go +++ b/99_svcc/43_sessions_GORILLA_JSON/main.go @@ -1,12 +1,12 @@ package main import ( - "github.com/gorilla/sessions" - "io" - "net/http" "encoding/json" "fmt" "github.com/gorilla/context" + "github.com/gorilla/sessions" + "io" + "net/http" ) var store = sessions.NewCookieStore([]byte("secret-password")) @@ -16,17 +16,16 @@ func authenticate(res http.ResponseWriter, req *http.Request) { // check log in if req.Method == "POST" && - req.FormValue("password") != "" { + req.FormValue("password") != "" { password := req.FormValue("password") if password == "secret" { session.Values["loggedin"] = "true" } } - // add data if req.Method == "POST" && - req.FormValue("data") != "" { + req.FormValue("data") != "" { var data []string jsonData := session.Values["data"] fmt.Printf("Type jsonData: %T\n", jsonData) @@ -48,7 +47,7 @@ func authenticate(res http.ResponseWriter, req *http.Request) { // not logged in if session.Values["loggedin"] == "false" || - session.Values["loggedin"] == nil { + session.Values["loggedin"] == nil { html = ` @@ -86,9 +85,9 @@ func authenticate(res http.ResponseWriter, req *http.Request) {
-

`+ - fmt.Sprint("cookie data: ", session.Values["data"]) + - `

+

` + + fmt.Sprint("cookie data: ", session.Values["data"]) + + `

` } diff --git a/99_svcc/44_file-paths/main.go b/99_svcc/44_file-paths/main.go index 80e377a7..5346b938 100644 --- a/99_svcc/44_file-paths/main.go +++ b/99_svcc/44_file-paths/main.go @@ -1,8 +1,9 @@ package main + import ( + "fmt" "os" "path/filepath" - "fmt" ) func main() { diff --git a/99_svcc/45_sessions_GORILLA_photo-blog/main.go b/99_svcc/45_sessions_GORILLA_photo-blog/main.go index e0644e85..d38dc06a 100644 --- a/99_svcc/45_sessions_GORILLA_photo-blog/main.go +++ b/99_svcc/45_sessions_GORILLA_photo-blog/main.go @@ -4,6 +4,7 @@ import ( "crypto/sha1" "encoding/json" "fmt" + "github.com/gorilla/context" "github.com/gorilla/sessions" "html/template" "io" @@ -11,7 +12,6 @@ import ( "net/http" "os" "path/filepath" - "github.com/gorilla/context" ) var tpl *template.Template diff --git a/99_svcc/46_HTTPS-TLS/main.go b/99_svcc/46_HTTPS-TLS/main.go index 3dc17f11..c132b7ec 100644 --- a/99_svcc/46_HTTPS-TLS/main.go +++ b/99_svcc/46_HTTPS-TLS/main.go @@ -30,4 +30,4 @@ go run $(go env GOROOT)/src/crypto/tls/generate_cert.go --host=somedomainname.co eg go run $(go env GOROOT)/src/crypto/tls/generate_cert.go --host=localhost -*/ \ No newline at end of file +*/