Skip to content

Commit ea35821

Browse files
Fixed examples and only keeping what is in the book.
1 parent b7f546c commit ea35821

15 files changed

Lines changed: 38 additions & 570 deletions

File tree

‎chapter1/channels/hellochannels.go‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
package main
22

33
import (
4-
"fmt"
5-
"sync"
4+
"fmt"
5+
"sync"
66
)
77

8-
var wg sync.WaitGroup //<co id="createwg" />
8+
var wg sync.WaitGroup
99

1010
func printer(ch chan int) {
11-
for i := range ch {
12-
fmt.Printf("Received %d ", i) //<co id="receivevalue" />
13-
}
14-
wg.Done()
11+
for i := range ch {
12+
fmt.Printf("Received %d ", i)
13+
}
14+
wg.Done()
1515
}
1616

1717
func main() {
18-
c := make(chan int) //<co id="createchan" />
19-
go printer(c) //<co id="goroutine" />
20-
wg.Add(1) //<co id="addwg" />
18+
c := make(chan int)
19+
go printer(c)
20+
wg.Add(1)
2121

22-
//Send 10 integers on the channel.
23-
for i := 1; i <= 10; i++ {
24-
c <- i //<co id="sendonchan" />
25-
}
22+
// Send 10 integers on the channel.
23+
for i := 1; i <= 10; i++ {
24+
c <- i
25+
}
2626

27-
close(c) //<co id="closechan" />
28-
wg.Wait() //<co id="wgwait" />
27+
close(c)
28+
wg.Wait()
2929
}

‎chapter3/arrays/arrays.go‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

‎chapter3/dbdriver/main.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// Sample program to show how to show you how to briefly work
2+
// with the sql package.
13
package main
24

35
import (
4-
_ "chapter2/dbdriver/postgres" //<co id="anon-import" />
56
"database/sql"
7+
8+
_ "github.com/goinaction/code/chapter3/dbdriver/postgres"
69
)
710

11+
// main is the entry point for the application.
812
func main() {
9-
sql.Open("postgres", "mydb") //<co id="sql-open" />
13+
sql.Open("postgres", "mydb")
1014
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//<start id="init"/>
21
package postgres
32

43
import (
@@ -7,17 +6,19 @@ import (
76
"errors"
87
)
98

10-
func init() {
11-
d = new(PostgresDriver) //<co id="driver-create" />
12-
sql.Register("postgres", d)
13-
}
14-
15-
//<end id="init"/>
16-
9+
// PostgresDriver provides our implementation for the
10+
// sql package.
1711
type PostgresDriver struct{}
1812

13+
// Open provides a connection to the database.
1914
func (dr PostgresDriver) Open(string) (driver.Conn, error) {
2015
return nil, errors.New("Unimplemented")
2116
}
2217

2318
var d *PostgresDriver
19+
20+
// init is called prior to main.
21+
func init() {
22+
d = new(PostgresDriver)
23+
sql.Register("postgres", d)
24+
}

‎chapter3/flow/flow.go‎

Lines changed: 0 additions & 137 deletions
This file was deleted.

‎chapter3/flow/select.go‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)