Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
81672ef1
Commit
81672ef1
authored
Sep 30, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some typos, mostly
R=gri OCL=16161 CL=16161
parent
1f3e842c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
4 deletions
+6
-4
go_tutorial.txt
doc/go_tutorial.txt
+5
-3
sieve.go
doc/progs/sieve.go
+1
-1
No files found.
doc/go_tutorial.txt
View file @
81672ef1
...
...
@@ -348,7 +348,7 @@ we have a second implementation of the "Reader" interface.
--PROG progs/cat_rot13.go /type.Rot13/ /end.of.Rot13/
(The "rot13" function called on line 3
9
is trivial and not worth reproducing.)
(The "rot13" function called on line 3
8
is trivial and not worth reproducing.)
To use the new feature, we define a flag:
...
...
@@ -358,6 +358,8 @@ and use it from within a mostly unchanged "cat()" function:
--PROG progs/cat_rot13.go /func.cat/ /^}/
(We could also do the wrapping in "main" and leave "cat()" mostly alone, except
for changing the type of the argument.)
Lines 53 and 54 set it all up: If the "rot13" flag is true, wrap the "Reader"
we received into a "Rot13" and proceed. Note that the interface variables
are values, not pointers: the argument is of type "Reader", not "*Reader",
...
...
@@ -374,7 +376,7 @@ Here it is in action:
</pre>
Fans of dependency injection may take cheer from how easily interfaces
made substituting
the implementation of a file descriptor.
allow us to substitute
the implementation of a file descriptor.
Interfaces are a distinct feature of Go. An interface is implemented by a
type if the type implements all the methods declared in the interface.
...
...
@@ -526,7 +528,7 @@ With channels, it's possible to serve multiple independent client goroutines wit
writing an actual multiplexer. The trick is to send the server a channel in the message,
which it will then use to reply to the original sender.
A realistic client-server program is a lot of code, so here is a very simple substitute
to illustrate the idea. It starts by defining "Request" type, which embeds a channel
to illustrate the idea. It starts by defining
a
"Request" type, which embeds a channel
that will be used for the reply.
--PROG progs/server.go /type.Request/ /^}/
...
...
doc/progs/sieve.go
View file @
81672ef1
...
...
@@ -13,7 +13,7 @@ func Generate(ch *chan int) {
// Copy the values from channel 'in' to channel 'out',
// removing those divisible by 'prime'.
func
Filter
(
in
*
chan
int
,
out
*
chan
int
,
prime
int
)
{
func
Filter
(
in
,
out
*
chan
int
,
prime
int
)
{
for
{
i
:=
<-
in
// Receive value of new variable 'i' from 'in'.
if
i
%
prime
!=
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment