Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
468e692e
Commit
468e692e
authored
Jan 09, 2012
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: only trim newlines in tmpltohtml, gofmt progs
R=golang-dev, r, r CC=golang-dev
https://golang.org/cl/5530048
parent
c7e91724
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
43 additions
and
29 deletions
+43
-29
doc/articles/error_handling.html
doc/articles/error_handling.html
+5
-5
doc/go1.html
doc/go1.html
+9
-9
doc/go_tutorial.html
doc/go_tutorial.html
+9
-10
doc/progs/cat_rot13.go
doc/progs/cat_rot13.go
+2
-1
doc/progs/defer2.go
doc/progs/defer2.go
+2
-0
doc/progs/echo.go
doc/progs/echo.go
+1
-1
doc/progs/error.go
doc/progs/error.go
+5
-0
doc/progs/error2.go
doc/progs/error2.go
+1
-0
doc/progs/error3.go
doc/progs/error3.go
+3
-0
doc/progs/error4.go
doc/progs/error4.go
+3
-0
doc/progs/go1.go
doc/progs/go1.go
+1
-0
doc/progs/sortmain.go
doc/progs/sortmain.go
+1
-2
doc/tmpltohtml.go
doc/tmpltohtml.go
+1
-1
No files found.
doc/articles/error_handling.html
View file @
468e692e
...
...
@@ -20,7 +20,7 @@ occurs it calls <code>log.Fatal</code> to print the error message and stop.
</p>
<pre>
<!--{{code "progs/error.go" `/func openFile/` `/STOP/`}}
-->
f, err := os.Open(
"
filename.ext
"
)
-->
f, err := os.Open(
"
filename.ext
"
)
if err != nil {
log.Fatal(err)
}
...
...
@@ -100,7 +100,7 @@ A caller passing a negative argument to <code>Sqrt</code> receives a non-nil
</p>
<pre>
<!--{{code "progs/error.go" `/func printErr/` `/STOP/`}}
-->
f, err := Sqrt(-1)
-->
f, err := Sqrt(-1)
if err != nil {
fmt.Println(err)
}
</pre>
...
...
@@ -125,7 +125,7 @@ rules and returns it as an <code>error</code> created by
</p>
<pre>
<!--{{code "progs/error.go" `/fmtError/` `/STOP/`}}
-->
if f
<
0 {
-->
if f
<
0 {
return 0, fmt.Errorf(
"
math: square root of negative number %g
"
, f)
}
</pre>
...
...
@@ -177,7 +177,7 @@ messages:
</p>
<pre>
<!--{{code "progs/error.go" `/func decodeError/` `/STOP/`}}
-->
if err := dec.Decode(
&
val); err != nil {
-->
if err := dec.Decode(
&
val); err != nil {
if serr, ok := err.(*json.SyntaxError); ok {
line, col := findLine(f, serr.Offset)
return fmt.Errorf(
"
%s:%d:%d: %v
"
, f.Name(), line, col, err)
...
...
@@ -216,7 +216,7 @@ up otherwise.
</p>
<pre>
<!--{{code "progs/error.go" `/func netError/` `/STOP/`}}
-->
if nerr, ok := err.(net.Error); ok
&&
nerr.Temporary() {
-->
if nerr, ok := err.(net.Error); ok
&&
nerr.Temporary() {
time.Sleep(1e9)
continue
}
...
...
doc/go1.html
View file @
468e692e
...
...
@@ -44,7 +44,7 @@ call.
</p>
<pre>
<!--{{code "progs/go1.go" `/greeting := ..byte/` `/append.*hello/`}}
-->
greeting := []byte{}
-->
greeting := []byte{}
greeting = append(greeting, []byte(
"
hello
"
)...)
</pre>
<p>
...
...
@@ -54,7 +54,7 @@ slice; the conversion is no longer necessary:
</p>
<pre>
<!--{{code "progs/go1.go" `/append.*world/`}}
-->
greeting = append(greeting,
"
world
"
...)
</pre>
-->
greeting = append(greeting,
"
world
"
...)
</pre>
<p>
<em>
Updating
</em>
:
...
...
@@ -95,7 +95,7 @@ All four of the initializations in this example are legal; the last one was ille
</p>
<pre>
<!--{{code "progs/go1.go" `/type Date struct/` `/STOP/`}}
-->
type Date struct {
-->
type Date struct {
month string
day int
}
...
...
@@ -182,7 +182,7 @@ relatives now take and return a <code>rune</code>.
</p>
<pre>
<!--{{code "progs/go1.go" `/STARTRUNE/` `/ENDRUNE/`}}
-->
delta :=
'
δ
'
// delta has type rune.
-->
delta :=
'
δ
'
// delta has type rune.
var DELTA rune
DELTA = unicode.ToUpper(delta)
epsilon := unicode.ToLower(DELTA + 1)
...
...
@@ -231,7 +231,7 @@ function, <code>delete</code>. The call
</p>
<pre>
<!--{{code "progs/go1.go" `/delete\(m, k\)/`}}
-->
delete(m, k)
</pre>
-->
delete(m, k)
</pre>
<p>
will delete the map entry retrieved by the expression
<code>
m[k]
</code>
.
...
...
@@ -258,7 +258,7 @@ Code should not assume that the elements are visited in any particular order.
</p>
<pre>
<!--{{code "progs/go1.go" `/Sunday/` `/^ }/`}}
-->
m := map[string]int{
"
Sunday
"
: 0,
"
Monday
"
: 1}
-->
m := map[string]int{
"
Sunday
"
: 0,
"
Monday
"
: 1}
for name, value := range m {
// This loop should not assume Sunday will be visited first.
f(name, value)
...
...
@@ -292,7 +292,7 @@ These examples illustrate the behavior.
</p>
<pre>
<!--{{code "progs/go1.go" `/sa :=/` `/then sc.0. = 2/`}}
-->
sa := []int{1, 2, 3}
-->
sa := []int{1, 2, 3}
i := 0
i, sa[i] = 1, 2 // sets i = 1, sa[0] = 2
...
...
@@ -409,7 +409,7 @@ As a result, structs and arrays can now be used as map keys:
</p>
<pre>
<!--{{code "progs/go1.go" `/type Day struct/` `/Printf/`}}
-->
type Day struct {
-->
type Day struct {
long string
short string
}
...
...
@@ -585,7 +585,7 @@ to turn a string into an error. It replaces the old <code>os.NewError</code>.
</p>
<pre>
<!--{{code "progs/go1.go" `/ErrSyntax/`}}
-->
var ErrSyntax = errors.New(
"
syntax error
"
)
</pre>
-->
var ErrSyntax = errors.New(
"
syntax error
"
)
</pre>
<p>
<em>
Updating
</em>
:
...
...
doc/go_tutorial.html
View file @
468e692e
...
...
@@ -119,8 +119,8 @@ Next up, here's a version of the Unix utility <code>echo(1)</code>:
-->
package main
import (
"
os
"
"
flag
"
// command line option parser
"
os
"
)
var omitNewline = flag.Bool(
"
n
"
, false,
"
don
'
t print final newline
"
)
...
...
@@ -209,7 +209,7 @@ The <code>:=</code> operator is used a lot in Go to represent an initializing de
There's one in the
<code>
for
</code>
clause on the next line:
<p>
<pre>
<!--{{code "progs/echo.go" `/for/`}}
-->
for i := 0; i
<
flag.NArg(); i++ {
</pre>
-->
for i := 0; i
<
flag.NArg(); i++ {
</pre>
<p>
The
<code>
flag
</code>
package has parsed the arguments and left the non-flag arguments
in a list that can be iterated over in the obvious way.
...
...
@@ -258,7 +258,7 @@ of course you can change a string <i>variable</i> simply by
reassigning it. This snippet from
<code>
strings.go
</code>
is legal code:
<p>
<pre>
<!--{{code "progs/strings.go" `/hello/` `/ciao/`}}
-->
s :=
"
hello
"
-->
s :=
"
hello
"
if s[1] !=
'
e
'
{
os.Exit(1)
}
...
...
@@ -811,8 +811,7 @@ func (r13 *rotate13) Read(b []byte) (ret int, err error) {
func (r13 *rotate13) String() string {
return r13.source.String()
}
// end of rotate13 implementation
</pre>
}
</pre>
<p>
(The
<code>
rot13
</code>
function called in
<code>
Read
</code>
is trivial and not worth reproducing here.)
<p>
...
...
@@ -990,7 +989,7 @@ can just say <code>%d</code>; <code>Printf</code> knows the size and signedness
integer and can do the right thing for you. The snippet
<p>
<pre>
<!--{{code "progs/print.go" 10 11}}
-->
var u64 uint64 = 1
<<
64 - 1
-->
var u64 uint64 = 1
<<
64 - 1
fmt.Printf(
"
%d %d\n
"
, u64, int64(u64))
</pre>
<p>
prints
...
...
@@ -1003,7 +1002,7 @@ In fact, if you're lazy the format <code>%v</code> will print, in a simple
appropriate style, any value, even an array or structure. The output of
<p>
<pre>
<!--{{code "progs/print.go" 14 20}}
-->
type T struct {
-->
type T struct {
a int
b string
}
...
...
@@ -1025,7 +1024,7 @@ and adds a newline. The output of each of these two lines is identical
to that of the
<code>
Printf
</code>
call above.
<p>
<pre>
<!--{{code "progs/print.go" 21 22}}
-->
fmt.Print(u64,
"
"
, t,
"
"
, a,
"
\n
"
)
-->
fmt.Print(u64,
"
"
, t,
"
"
, a,
"
\n
"
)
fmt.Println(u64, t, a)
</pre>
<p>
If you have your own type you'd like
<code>
Printf
</code>
or
<code>
Print
</code>
to format,
...
...
@@ -1442,10 +1441,10 @@ All that's left is to strobe the <code>quit</code> channel
at the end of main:
<p>
<pre>
<!--{{code "progs/server1.go" `/adder,.quit/`}}
-->
adder, quit := startServer(func(a, b int) int { return a + b })
</pre>
-->
adder, quit := startServer(func(a, b int) int { return a + b })
</pre>
...
<pre>
<!--{{code "progs/server1.go" `/quit....true/`}}
-->
quit
<
- true
</pre>
-->
quit
<
- true
</pre>
<p>
There's a lot more to Go programming and concurrent programming in general but this
quick tour should give you some of the basics.
doc/progs/cat_rot13.go
View file @
468e692e
...
...
@@ -47,7 +47,8 @@ func (r13 *rotate13) Read(b []byte) (ret int, err error) {
func
(
r13
*
rotate13
)
String
()
string
{
return
r13
.
source
.
String
()
}
// end of rotate13 implementation
// end of rotate13 implementation OMIT
func
cat
(
r
reader
)
{
const
NBUF
=
512
...
...
doc/progs/defer2.go
View file @
468e692e
...
...
@@ -35,6 +35,7 @@ func g(i int) {
fmt
.
Println
(
"Printing in g"
,
i
)
g
(
i
+
1
)
}
// STOP OMIT
// Revised version.
...
...
@@ -53,4 +54,5 @@ func CopyFile(dstName, srcName string) (written int64, err error) {
return
io
.
Copy
(
dst
,
src
)
}
// STOP OMIT
doc/progs/echo.go
View file @
468e692e
...
...
@@ -5,8 +5,8 @@
package
main
import
(
"os"
"flag"
// command line option parser
"os"
)
var
omitNewline
=
flag
.
Bool
(
"n"
,
false
,
"don't print final newline"
)
...
...
doc/progs/error.go
View file @
468e692e
...
...
@@ -38,12 +38,14 @@ type errorString struct {
func
(
e
*
errorString
)
Error
()
string
{
return
e
.
s
}
// STOP OMIT
// New returns an error that formats as the given text.
func
New
(
text
string
)
error
{
return
&
errorString
{
text
}
}
// STOP OMIT
func
Sqrt
(
f
float64
)
(
float64
,
error
)
{
...
...
@@ -53,6 +55,7 @@ func Sqrt(f float64) (float64, error) {
// implementation
return
0
,
nil
// OMIT
}
// STOP OMIT
func
printErr
()
(
int
,
error
)
{
// OMIT
...
...
@@ -74,6 +77,7 @@ type NegativeSqrtError float64
func
(
f
NegativeSqrtError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"math: square root of negative number %g"
,
float64
(
f
))
}
// STOP OMIT
type
SyntaxError
struct
{
...
...
@@ -82,6 +86,7 @@ type SyntaxError struct {
}
func
(
e
*
SyntaxError
)
Error
()
string
{
return
e
.
msg
}
// STOP OMIT
func
decodeError
(
dec
*
json
.
Decoder
,
val
struct
{})
error
{
// OMIT
...
...
doc/progs/error2.go
View file @
468e692e
...
...
@@ -27,6 +27,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) {
http
.
Error
(
w
,
err
.
Error
(),
500
)
}
}
// STOP OMIT
type
ap
struct
{}
...
...
doc/progs/error3.go
View file @
468e692e
...
...
@@ -14,6 +14,7 @@ import (
func
init
()
{
http
.
Handle
(
"/view"
,
appHandler
(
viewRecord
))
}
// STOP OMIT
func
viewRecord
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
error
{
...
...
@@ -25,6 +26,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) error {
}
return
viewTemplate
.
Execute
(
w
,
record
)
}
// STOP OMIT
type
appHandler
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
error
...
...
@@ -34,6 +36,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http
.
Error
(
w
,
err
.
Error
(),
500
)
}
}
// STOP OMIT
type
ap
struct
{}
...
...
doc/progs/error4.go
View file @
468e692e
...
...
@@ -16,6 +16,7 @@ type appError struct {
Message
string
Code
int
}
// STOP OMIT
type
appHandler
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
*
appError
...
...
@@ -27,6 +28,7 @@ func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http
.
Error
(
w
,
e
.
Message
,
e
.
Code
)
}
}
// STOP OMIT
func
viewRecord
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
*
appError
{
...
...
@@ -41,6 +43,7 @@ func viewRecord(w http.ResponseWriter, r *http.Request) *appError {
}
return
nil
}
// STOP OMIT
func
init
()
{
...
...
doc/progs/go1.go
View file @
468e692e
...
...
@@ -147,6 +147,7 @@ type SyntaxError struct {
func
(
se
*
SyntaxError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"%s:%d: %s"
,
se
.
File
,
se
.
Line
,
se
.
Message
)
}
// END ERROR EXAMPLE OMIT
func
errorExample
()
{
...
...
doc/progs/sortmain.go
View file @
468e692e
...
...
@@ -5,8 +5,8 @@
package
main
import
(
"fmt"
"./sort"
"fmt"
)
func
ints
()
{
...
...
@@ -61,7 +61,6 @@ func days() {
fmt
.
Printf
(
"
\n
"
)
}
func
main
()
{
ints
()
strings
()
...
...
doc/tmpltohtml.go
View file @
468e692e
...
...
@@ -114,7 +114,7 @@ func code(file string, arg ...interface{}) (string, error) {
return
""
,
fmt
.
Errorf
(
"incorrect code invocation: code %q %q"
,
file
,
arg
)
}
// Trim spaces from output.
text
=
strings
.
Trim
Space
(
text
)
text
=
strings
.
Trim
(
text
,
"
\n
"
)
// Replace tabs by spaces, which work better in HTML.
text
=
strings
.
Replace
(
text
,
"
\t
"
,
" "
,
-
1
)
// Escape the program text for HTML.
...
...
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