File tree 5 files changed +20
-9
lines changed
05_blank-identifier/02_http-get_example
21_interfaces/01_interface/02_interface
22_go-routines/13_channels_fan-out_fan-in/05_challenge-solution
5 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"github.com/GoesToEleven/GolangTraining/02_package/stringutil"
6
6
"github.com/GoesToEleven/GolangTraining/02_package/icomefromalaska"
7
+ //someAlias "github.com/GoesToEleven/GolangTraining/02_package/icomefromalaska"
7
8
)
8
9
9
10
func main () {
Original file line number Diff line number Diff line change 8
8
)
9
9
10
10
func main () {
11
- res , err := http .Get ("http://www.mcleods .com/" )
11
+ res , err := http .Get ("http://www.geekwiseacademy .com/" )
12
12
if err != nil {
13
13
log .Fatal (err )
14
14
}
Original file line number Diff line number Diff line change 7
7
)
8
8
9
9
func main () {
10
- res , _ := http .Get ("http://www.mcleods .com/" )
10
+ res , _ := http .Get ("http://www.geekwiseacademy .com/" )
11
11
page , _ := ioutil .ReadAll (res .Body )
12
12
res .Body .Close ()
13
13
fmt .Printf ("%s" , page )
14
- }
14
+ }
Original file line number Diff line number Diff line change @@ -21,5 +21,6 @@ func info(z shape) {
21
21
22
22
func main () {
23
23
s := square {10 }
24
+ fmt .Printf ("%T\n " ,s )
24
25
info (s )
25
26
}
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ package main
3
3
import (
4
4
"fmt"
5
5
"time"
6
+ "sync/atomic"
6
7
)
7
8
8
- var workerID int
9
- var publisherID int
9
+ var workerID int64
10
+ var publisherID int64
10
11
11
12
func main () {
12
13
input := make (chan string )
@@ -22,8 +23,12 @@ func main() {
22
23
23
24
// publisher pushes data into a channel
24
25
func publisher (out chan string ) {
25
- publisherID ++
26
- thisID := publisherID
26
+ atomic .AddInt64 (& publisherID , 1 )
27
+ // atomic was added after recording to fix a race condition
28
+ // discover race conditions with the -race flag
29
+ // for example: go run -race main.go
30
+ // learn about the atomic package: https://godoc.org/sync/atomic#AddInt64
31
+ thisID := atomic .LoadInt64 (& publisherID )
27
32
dataID := 0
28
33
for {
29
34
dataID ++
@@ -34,8 +39,12 @@ func publisher(out chan string) {
34
39
}
35
40
36
41
func workerProcess (in <- chan string ) {
37
- workerID ++
38
- thisID := workerID
42
+ atomic .AddInt64 (& workerID , 1 )
43
+ // atomic was added after recording to fix a race condition
44
+ // discover race conditions with the -race flag
45
+ // for example: go run -race main.go
46
+ // learn about the atomic package: https://godoc.org/sync/atomic#AddInt64
47
+ thisID := atomic .LoadInt64 (& workerID )
39
48
for {
40
49
fmt .Printf ("%d: waiting for input...\n " , thisID )
41
50
input := <- in
You can’t perform that action at this time.
0 commit comments