Skip to content

Commit 088c776

Browse files
added links and fixed docs
1 parent 72fb3a4 commit 088c776

File tree

4 files changed

+70
-32
lines changed

4 files changed

+70
-32
lines changed

Opening.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Slack: [Slack](https://invite.slack.golangbridge.org)
1717
Graphviz: https://www.graphviz.org/
1818
go get -u github.com/rakyll/hey : Or use ab
1919
go get -u github.com/ardanlabs/gotraining
20-
Latest Version of Go: 1.11
20+
Latest Version of Go: 1.12

reading/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,28 @@ There is a ton of links to extra reading and videos through out the material. Oc
111111
[Go’s hidden #pragmas](https://dave.cheney.net/2018/01/08/gos-hidden-pragmas) - Dave Cheney
112112
[Post-mortem debugging of Go Programs](https://fntlnz.wtf/post/gopostmortem/) - Lorenzo Fontana
113113
[A Crash Course in Modern Hardware](https://www.youtube.com/watch?v=OFgxAFdxYAQ) - Cliff Click
114+
[How I investigated memory leaks in Go using pprof on a large codebase](https://medium.freecodecamp.org/how-i-investigated-memory-leaks-in-go-using-pprof-on-a-large-codebase-4bec4325e192) - Jonathan Levison
114115

115116
### API Design
116117

117118
[You wanted a banana but you got a gorilla holding the banana](http://www.johndcook.com/blog/2011/07/19/you-wanted-banana) - John D. Cook
118119
[Focus On Being Precise](https://www.ardanlabs.com/blog/2018/02/focus-on-being-precise.html) - William Kennedy
119120
[Design, Composition and Performance](https://www.infoq.com/presentations/Design-Composition-Performance) - Rich Hickey
120121

122+
### Error Handling
123+
124+
[Go 1.13: xerrors](https://crawshaw.io/blog/xerrors) - David Crawshaw
125+
[Error handling and Go](https://blog.golang.org/error-handling-and-go)
126+
[Error Handling In Go, Part I](https://www.ardanlabs.com/blog/2014/10/error-handling-in-go-part-i.html) - William Kennedy
127+
[Error Handling In Go, Part II](https://www.ardanlabs.com/blog/2014/11/error-handling-in-go-part-ii.html) - William Kennedy
128+
[Design Philosophy On Logging](https://www.ardanlabs.com/blog/2017/05/design-philosophy-on-logging.html) - William Kennedy
129+
[Bugs are a failure of prediction](https://clipperhouse.com/bugs-are-a-failure-of-prediction/) - Matt Sherman
130+
[Inspecting errors](https://dave.cheney.net/2014/12/24/inspecting-errors) - Dave Cheney
131+
[Don’t just check errors, handle them gracefully](https://dave.cheney.net/2016/04/27/dont-just-check-errors-handle-them-gracefully) - Dave Cheney
132+
[Stack traces and the errors package](https://dave.cheney.net/2016/06/12/stack-traces-and-the-errors-package) - Dave Cheney
133+
[Errors are handled in return values](https://plus.google.com/+RussCox-rsc/posts/iqAiKAwP6Ce) - Russ Cox
134+
[Error handling in Upspin](https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html) - Rob Pike
135+
121136
### Interfaces and Composition
122137

123138
[Repeat yourself, do more than one thing, and rewrite everything](https://programmingisterrible.com/post/176657481103/repeat-yourself-do-more-than-one-thing-and) - tef

topics/go/design/error_handling/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _Systems cannot be developed assuming that human beings will be able to write mi
2525
[Stack traces and the errors package](https://dave.cheney.net/2016/06/12/stack-traces-and-the-errors-package) - Dave Cheney
2626
[Errors are handled in return values](https://plus.google.com/+RussCox-rsc/posts/iqAiKAwP6Ce) - Russ Cox
2727
[Error handling in Upspin](https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html) - Rob Pike
28+
[Go 1.13: xerrors](https://crawshaw.io/blog/xerrors) - David Crawshaw
2829

2930
## Code Review
3031

topics/go/profiling/trace/trace.go

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func main() {
4141
// pprof.StartCPUProfile(os.Stdout)
4242
// defer pprof.StopCPUProfile()
4343

44-
// trace.Start(os.Stdout)
45-
// defer trace.Stop()
44+
trace.Start(os.Stdout)
45+
defer trace.Stop()
4646

4747
docs := make([]string, 4000)
4848
for i := range docs {
@@ -62,43 +62,65 @@ func main() {
6262
}
6363

6464
func find(topic string, docs []string) int {
65-
var found int
65+
var found int32
6666

67-
for _, doc := range docs {
68-
file := fmt.Sprintf("%s.xml", doc[:8])
69-
f, err := os.OpenFile(file, os.O_RDONLY, 0)
70-
if err != nil {
71-
log.Printf("Opening Document [%s] : ERROR : %v", doc, err)
72-
return 0
73-
}
67+
g := runtime.NumCPU()
68+
var wg sync.WaitGroup
69+
wg.Add(g)
7470

75-
data, err := ioutil.ReadAll(f)
76-
if err != nil {
77-
f.Close()
78-
log.Printf("Reading Document [%s] : ERROR : %v", doc, err)
79-
return 0
80-
}
81-
f.Close()
71+
ch := make(chan string, g)
8272

83-
var d document
84-
if err := xml.Unmarshal(data, &d); err != nil {
85-
log.Printf("Decoding Document [%s] : ERROR : %v", doc, err)
86-
return 0
87-
}
73+
for i := 0; i < g; i++ {
74+
go func() {
75+
var lFound int32
76+
defer func() {
77+
atomic.AddInt32(&found, lFound)
78+
wg.Done()
79+
}()
8880

89-
for _, item := range d.Channel.Items {
90-
if strings.Contains(item.Title, topic) {
91-
found++
92-
continue
93-
}
81+
for doc := range ch {
82+
file := fmt.Sprintf("%s.xml", doc[:8])
83+
f, err := os.OpenFile(file, os.O_RDONLY, 0)
84+
if err != nil {
85+
log.Printf("Opening Document [%s] : ERROR : %v", doc, err)
86+
return
87+
}
88+
89+
data, err := ioutil.ReadAll(f)
90+
if err != nil {
91+
f.Close()
92+
log.Printf("Reading Document [%s] : ERROR : %v", doc, err)
93+
return
94+
}
95+
f.Close()
96+
97+
var d document
98+
if err := xml.Unmarshal(data, &d); err != nil {
99+
log.Printf("Decoding Document [%s] : ERROR : %v", doc, err)
100+
return
101+
}
102+
103+
for _, item := range d.Channel.Items {
104+
if strings.Contains(item.Title, topic) {
105+
lFound++
106+
continue
107+
}
94108

95-
if strings.Contains(item.Description, topic) {
96-
found++
109+
if strings.Contains(item.Description, topic) {
110+
lFound++
111+
}
112+
}
97113
}
98-
}
114+
}()
99115
}
100116

101-
return found
117+
for _, doc := range docs {
118+
ch <- doc
119+
}
120+
close(ch)
121+
122+
wg.Wait()
123+
return int(found)
102124
}
103125

104126
func findConcurrent(topic string, docs []string) int {

0 commit comments

Comments
 (0)