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
44526cdb
Commit
44526cdb
authored
Nov 01, 2011
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
non-pkg: gofix -r error -force=error
R=golang-dev, iant, r, r CC=golang-dev
https://golang.org/cl/5307066
parent
eb692929
Changes
63
Hide whitespace changes
Inline
Side-by-side
Showing
63 changed files
with
300 additions
and
320 deletions
+300
-320
doc/codelab/wiki/final-noclosure.go
doc/codelab/wiki/final-noclosure.go
+9
-9
doc/codelab/wiki/final-noerror.go
doc/codelab/wiki/final-noerror.go
+2
-3
doc/codelab/wiki/final-parsetemplate.go
doc/codelab/wiki/final-parsetemplate.go
+5
-6
doc/codelab/wiki/final-template.go
doc/codelab/wiki/final-template.go
+2
-3
doc/codelab/wiki/final.go
doc/codelab/wiki/final.go
+5
-6
doc/codelab/wiki/get.go
doc/codelab/wiki/get.go
+1
-1
doc/codelab/wiki/index.html
doc/codelab/wiki/index.html
+10
-10
doc/codelab/wiki/notemplate.go
doc/codelab/wiki/notemplate.go
+2
-3
doc/codelab/wiki/part1-noerror.go
doc/codelab/wiki/part1-noerror.go
+1
-2
doc/codelab/wiki/part1.go
doc/codelab/wiki/part1.go
+2
-3
doc/codelab/wiki/part2.go
doc/codelab/wiki/part2.go
+2
-3
doc/codewalk/urlpoll.go
doc/codewalk/urlpoll.go
+1
-1
doc/go_tutorial.html
doc/go_tutorial.html
+9
-9
doc/progs/cat_rot13.go
doc/progs/cat_rot13.go
+2
-2
doc/progs/file.go
doc/progs/file.go
+6
-6
doc/progs/file_windows.go
doc/progs/file_windows.go
+6
-6
doc/progs/helloworld3.go
doc/progs/helloworld3.go
+1
-1
doc/talks/io2010/decrypt.go
doc/talks/io2010/decrypt.go
+2
-2
doc/talks/io2010/encrypt.go
doc/talks/io2010/encrypt.go
+1
-1
doc/tmpltohtml.go
doc/tmpltohtml.go
+1
-2
misc/cgo/gmp/gmp.go
misc/cgo/gmp/gmp.go
+1
-1
misc/cgo/test/basic.go
misc/cgo/test/basic.go
+2
-2
misc/dashboard/builder/exec.go
misc/dashboard/builder/exec.go
+3
-3
misc/dashboard/builder/http.go
misc/dashboard/builder/http.go
+10
-10
misc/dashboard/builder/main.go
misc/dashboard/builder/main.go
+8
-7
misc/dashboard/builder/package.go
misc/dashboard/builder/package.go
+4
-3
misc/goplay/goplay.go
misc/goplay/goplay.go
+8
-8
src/cmd/cgo/ast.go
src/cmd/cgo/ast.go
+6
-6
src/cmd/cgo/gcc.go
src/cmd/cgo/gcc.go
+16
-15
src/cmd/cgo/main.go
src/cmd/cgo/main.go
+2
-2
src/cmd/cgo/out.go
src/cmd/cgo/out.go
+2
-2
src/cmd/cgo/util.go
src/cmd/cgo/util.go
+1
-1
src/cmd/godoc/appinit.go
src/cmd/godoc/appinit.go
+1
-2
src/cmd/godoc/codewalk.go
src/cmd/godoc/codewalk.go
+10
-9
src/cmd/godoc/filesystem.go
src/cmd/godoc/filesystem.go
+9
-9
src/cmd/godoc/godoc.go
src/cmd/godoc/godoc.go
+10
-10
src/cmd/godoc/httpzip.go
src/cmd/godoc/httpzip.go
+7
-7
src/cmd/godoc/index.go
src/cmd/godoc/index.go
+8
-8
src/cmd/godoc/main.go
src/cmd/godoc/main.go
+4
-3
src/cmd/godoc/parser.go
src/cmd/godoc/parser.go
+3
-4
src/cmd/godoc/utils.go
src/cmd/godoc/utils.go
+1
-1
src/cmd/godoc/zip.go
src/cmd/godoc/zip.go
+6
-7
src/cmd/gofix/main.go
src/cmd/gofix/main.go
+6
-6
src/cmd/gofmt/gofmt.go
src/cmd/gofmt/gofmt.go
+7
-7
src/cmd/goinstall/download.go
src/cmd/goinstall/download.go
+18
-17
src/cmd/goinstall/main.go
src/cmd/goinstall/main.go
+9
-8
src/cmd/goinstall/make.go
src/cmd/goinstall/make.go
+8
-8
src/cmd/gotest/gotest.go
src/cmd/gotest/gotest.go
+1
-1
src/cmd/govet/govet.go
src/cmd/govet/govet.go
+2
-2
src/cmd/hgpatch/main.go
src/cmd/hgpatch/main.go
+16
-16
test/chan/goroutines.go
test/chan/goroutines.go
+1
-1
test/env.go
test/env.go
+2
-2
test/fixedbugs/bug243.go
test/fixedbugs/bug243.go
+4
-4
test/fixedbugs/bug262.go
test/fixedbugs/bug262.go
+3
-4
test/fixedbugs/bug286.go
test/fixedbugs/bug286.go
+5
-9
test/fixedbugs/bug326.go
test/fixedbugs/bug326.go
+9
-11
test/fixedbugs/bug331.go
test/fixedbugs/bug331.go
+7
-7
test/fixedbugs/bug354.go
test/fixedbugs/bug354.go
+2
-6
test/func2.go
test/func2.go
+1
-2
test/garbage/parser.go
test/garbage/parser.go
+1
-1
test/recover2.go
test/recover2.go
+2
-5
test/recover3.go
test/recover3.go
+1
-1
test/zerodivide.go
test/zerodivide.go
+3
-3
No files found.
doc/codelab/wiki/final-noclosure.go
View file @
44526cdb
package
main
package
main
import
(
import
(
"errors"
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
"regexp"
"regexp"
"template"
"template"
)
)
...
@@ -13,12 +13,12 @@ type Page struct {
...
@@ -13,12 +13,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -61,21 +61,21 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -61,21 +61,21 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
err
=
p
.
save
()
err
=
p
.
save
()
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
}
}
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
t
,
err
:=
template
.
ParseFile
(
tmpl
+
".html"
)
t
,
err
:=
template
.
ParseFile
(
tmpl
+
".html"
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
err
=
t
.
Execute
(
w
,
p
)
err
=
t
.
Execute
(
w
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
}
}
}
...
@@ -83,11 +83,11 @@ const lenPath = len("/view/")
...
@@ -83,11 +83,11 @@ const lenPath = len("/view/")
var
titleValidator
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]+$"
)
var
titleValidator
=
regexp
.
MustCompile
(
"^[a-zA-Z0-9]+$"
)
func
getTitle
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
title
string
,
err
os
.
E
rror
)
{
func
getTitle
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
title
string
,
err
e
rror
)
{
title
=
r
.
URL
.
Path
[
lenPath
:
]
title
=
r
.
URL
.
Path
[
lenPath
:
]
if
!
titleValidator
.
MatchString
(
title
)
{
if
!
titleValidator
.
MatchString
(
title
)
{
http
.
NotFound
(
w
,
r
)
http
.
NotFound
(
w
,
r
)
err
=
os
.
NewError
(
"Invalid Page Title"
)
err
=
errors
.
New
(
"Invalid Page Title"
)
}
}
return
return
}
}
...
...
doc/codelab/wiki/final-noerror.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
"template"
"template"
)
)
...
@@ -12,12 +11,12 @@ type Page struct {
...
@@ -12,12 +11,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
doc/codelab/wiki/final-parsetemplate.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
"regexp"
"regexp"
"template"
"template"
)
)
...
@@ -13,12 +12,12 @@ type Page struct {
...
@@ -13,12 +12,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -49,7 +48,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
...
@@ -49,7 +48,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
err
:=
p
.
save
()
err
:=
p
.
save
()
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
...
@@ -58,12 +57,12 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
...
@@ -58,12 +57,12 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
t
,
err
:=
template
.
ParseFile
(
tmpl
+
".html"
,
nil
)
t
,
err
:=
template
.
ParseFile
(
tmpl
+
".html"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
err
=
t
.
Execute
(
w
,
p
)
err
=
t
.
Execute
(
w
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
}
}
}
...
...
doc/codelab/wiki/final-template.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
"template"
"template"
)
)
...
@@ -12,12 +11,12 @@ type Page struct {
...
@@ -12,12 +11,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
doc/codelab/wiki/final.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
"regexp"
"regexp"
"template"
"template"
)
)
...
@@ -13,12 +12,12 @@ type Page struct {
...
@@ -13,12 +12,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -49,7 +48,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
...
@@ -49,7 +48,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
p
:=
&
Page
{
Title
:
title
,
Body
:
[]
byte
(
body
)}
err
:=
p
.
save
()
err
:=
p
.
save
()
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
http
.
Redirect
(
w
,
r
,
"/view/"
+
title
,
http
.
StatusFound
)
...
@@ -59,7 +58,7 @@ var templates = make(map[string]*template.Template)
...
@@ -59,7 +58,7 @@ var templates = make(map[string]*template.Template)
func
init
()
{
func
init
()
{
for
_
,
tmpl
:=
range
[]
string
{
"edit"
,
"view"
}
{
for
_
,
tmpl
:=
range
[]
string
{
"edit"
,
"view"
}
{
t
:=
template
.
Must
(
template
.
ParseFile
(
tmpl
+
".html"
))
t
:=
template
.
Must
(
template
.
ParseFile
(
tmpl
+
".html"
))
templates
[
tmpl
]
=
t
templates
[
tmpl
]
=
t
}
}
}
}
...
@@ -67,7 +66,7 @@ func init() {
...
@@ -67,7 +66,7 @@ func init() {
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
func
renderTemplate
(
w
http
.
ResponseWriter
,
tmpl
string
,
p
*
Page
)
{
err
:=
templates
[
tmpl
]
.
Execute
(
w
,
p
)
err
:=
templates
[
tmpl
]
.
Execute
(
w
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
String
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
}
}
}
...
...
doc/codelab/wiki/get.go
View file @
44526cdb
...
@@ -32,7 +32,7 @@ func main() {
...
@@ -32,7 +32,7 @@ func main() {
log
.
Fatal
(
"no url supplied"
)
log
.
Fatal
(
"no url supplied"
)
}
}
var
r
*
http
.
Response
var
r
*
http
.
Response
var
err
os
.
E
rror
var
err
e
rror
if
*
post
!=
""
{
if
*
post
!=
""
{
b
:=
strings
.
NewReader
(
*
post
)
b
:=
strings
.
NewReader
(
*
post
)
r
,
err
=
http
.
Post
(
url
,
"application/x-www-form-urlencoded"
,
b
)
r
,
err
=
http
.
Post
(
url
,
"application/x-www-form-urlencoded"
,
b
)
...
...
doc/codelab/wiki/index.html
View file @
44526cdb
...
@@ -98,7 +98,7 @@ But what about persistent storage? We can address that by creating a
...
@@ -98,7 +98,7 @@ But what about persistent storage? We can address that by creating a
</p>
</p>
<pre>
<pre>
func (p *Page) save()
os.E
rror {
func (p *Page) save()
e
rror {
filename := p.Title +
"
.txt
"
filename := p.Title +
"
.txt
"
return ioutil.WriteFile(filename, p.Body, 0600)
return ioutil.WriteFile(filename, p.Body, 0600)
}
}
...
@@ -165,7 +165,7 @@ function to return <code>*Page</code> and <code>os.Error</code>.
...
@@ -165,7 +165,7 @@ function to return <code>*Page</code> and <code>os.Error</code>.
</p>
</p>
<pre>
<pre>
func loadPage(title string) (*Page,
os.E
rror) {
func loadPage(title string) (*Page,
e
rror) {
filename := title +
"
.txt
"
filename := title +
"
.txt
"
body, err := ioutil.ReadFile(filename)
body, err := ioutil.ReadFile(filename)
if err != nil {
if err != nil {
...
@@ -645,12 +645,12 @@ First, let's handle the errors in <code>renderTemplate</code>:
...
@@ -645,12 +645,12 @@ First, let's handle the errors in <code>renderTemplate</code>:
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
t, err := template.ParseFile(tmpl+
"
.html
"
, nil)
t, err := template.ParseFile(tmpl+
"
.html
"
, nil)
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
return
return
}
}
err = t.Execute(w, p)
err = t.Execute(w, p)
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
}
}
}
}
</pre>
</pre>
...
@@ -675,7 +675,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -675,7 +675,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p :=
&
Page{Title: title, Body: []byte(body)}
p :=
&
Page{Title: title, Body: []byte(body)}
err = p.save()
err = p.save()
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
return
return
}
}
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
...
@@ -741,7 +741,7 @@ the <code>Execute</code> method on the appropriate <code>Template</code> from
...
@@ -741,7 +741,7 @@ the <code>Execute</code> method on the appropriate <code>Template</code> from
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
func renderTemplate(w http.ResponseWriter, tmpl string, p *Page) {
err := templates[tmpl].Execute(w, p)
err := templates[tmpl].Execute(w, p)
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
}
}
}
}
</pre>
</pre>
...
@@ -777,11 +777,11 @@ URL, and tests it against our <code>TitleValidator</code> expression:
...
@@ -777,11 +777,11 @@ URL, and tests it against our <code>TitleValidator</code> expression:
</p>
</p>
<pre>
<pre>
func getTitle(w http.ResponseWriter, r *http.Request) (title string, err
os.E
rror) {
func getTitle(w http.ResponseWriter, r *http.Request) (title string, err
e
rror) {
title = r.URL.Path[lenPath:]
title = r.URL.Path[lenPath:]
if !titleValidator.MatchString(title) {
if !titleValidator.MatchString(title) {
http.NotFound(w, r)
http.NotFound(w, r)
err =
os.NewError
(
"
Invalid Page Title
"
)
err =
errors.New
(
"
Invalid Page Title
"
)
}
}
return
return
}
}
...
@@ -833,7 +833,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -833,7 +833,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request) {
p :=
&
Page{Title: title, Body: []byte(body)}
p :=
&
Page{Title: title, Body: []byte(body)}
err = p.save()
err = p.save()
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
return
return
}
}
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
...
@@ -958,7 +958,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
...
@@ -958,7 +958,7 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
p :=
&
Page{Title: title, Body: []byte(body)}
p :=
&
Page{Title: title, Body: []byte(body)}
err := p.save()
err := p.save()
if err != nil {
if err != nil {
http.Error(w, err.
String
(), http.StatusInternalServerError)
http.Error(w, err.
Error
(), http.StatusInternalServerError)
return
return
}
}
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
http.Redirect(w, r,
"
/view/
"
+title, http.StatusFound)
...
...
doc/codelab/wiki/notemplate.go
View file @
44526cdb
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"fmt"
"fmt"
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
)
)
type
Page
struct
{
type
Page
struct
{
...
@@ -12,12 +11,12 @@ type Page struct {
...
@@ -12,12 +11,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
doc/codelab/wiki/part1-noerror.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
)
)
type
Page
struct
{
type
Page
struct
{
...
@@ -11,7 +10,7 @@ type Page struct {
...
@@ -11,7 +10,7 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
...
...
doc/codelab/wiki/part1.go
View file @
44526cdb
...
@@ -3,7 +3,6 @@ package main
...
@@ -3,7 +3,6 @@ package main
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
)
)
type
Page
struct
{
type
Page
struct
{
...
@@ -11,12 +10,12 @@ type Page struct {
...
@@ -11,12 +10,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
doc/codelab/wiki/part2.go
View file @
44526cdb
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"fmt"
"fmt"
"http"
"http"
"io/ioutil"
"io/ioutil"
"os"
)
)
type
Page
struct
{
type
Page
struct
{
...
@@ -12,12 +11,12 @@ type Page struct {
...
@@ -12,12 +11,12 @@ type Page struct {
Body
[]
byte
Body
[]
byte
}
}
func
(
p
*
Page
)
save
()
os
.
E
rror
{
func
(
p
*
Page
)
save
()
e
rror
{
filename
:=
p
.
Title
+
".txt"
filename
:=
p
.
Title
+
".txt"
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
return
ioutil
.
WriteFile
(
filename
,
p
.
Body
,
0600
)
}
}
func
loadPage
(
title
string
)
(
*
Page
,
os
.
E
rror
)
{
func
loadPage
(
title
string
)
(
*
Page
,
e
rror
)
{
filename
:=
title
+
".txt"
filename
:=
title
+
".txt"
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
body
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
doc/codewalk/urlpoll.go
View file @
44526cdb
...
@@ -71,7 +71,7 @@ func (r *Resource) Poll() string {
...
@@ -71,7 +71,7 @@ func (r *Resource) Poll() string {
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
"Error"
,
r
.
url
,
err
)
log
.
Println
(
"Error"
,
r
.
url
,
err
)
r
.
errCount
++
r
.
errCount
++
return
err
.
String
()
return
err
.
Error
()
}
}
r
.
errCount
=
0
r
.
errCount
=
0
return
resp
.
Status
return
resp
.
Status
...
...
doc/go_tutorial.html
View file @
44526cdb
...
@@ -556,7 +556,7 @@ The <code>newFile</code> function was not exported because it's internal. The pr
...
@@ -556,7 +556,7 @@ The <code>newFile</code> function was not exported because it's internal. The pr
exported factory to use is
<code>
OpenFile
</code>
(we'll explain that name in a moment):
exported factory to use is
<code>
OpenFile
</code>
(we'll explain that name in a moment):
<p>
<p>
<pre>
<!--{{code "progs/file.go" `/func.OpenFile/` `/^}/`}}
<pre>
<!--{{code "progs/file.go" `/func.OpenFile/` `/^}/`}}
-->
func OpenFile(name string, mode int, perm uint32) (file *File, err
os.E
rror) {
-->
func OpenFile(name string, mode int, perm uint32) (file *File, err
e
rror) {
r, e := syscall.Open(name, mode, perm)
r, e := syscall.Open(name, mode, perm)
if e != 0 {
if e != 0 {
err = os.Errno(e)
err = os.Errno(e)
...
@@ -603,13 +603,13 @@ the tricky standard arguments to open and, especially, to create a file:
...
@@ -603,13 +603,13 @@ the tricky standard arguments to open and, especially, to create a file:
O_TRUNC = syscall.O_TRUNC
O_TRUNC = syscall.O_TRUNC
)
)
func Open(name string) (file *File, err
os.E
rror) {
func Open(name string) (file *File, err
e
rror) {
return OpenFile(name, O_RDONLY, 0)
return OpenFile(name, O_RDONLY, 0)
}
}
</pre>
</pre>
<p>
<p>
<pre>
<!--{{code "progs/file.go" `/func.Create/` `/^}/`}}
<pre>
<!--{{code "progs/file.go" `/func.Create/` `/^}/`}}
-->
func Create(name string) (file *File, err
os.E
rror) {
-->
func Create(name string) (file *File, err
e
rror) {
return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
}
}
</pre>
</pre>
...
@@ -622,7 +622,7 @@ in parentheses before the function name. Here are some methods for <code>*File</
...
@@ -622,7 +622,7 @@ in parentheses before the function name. Here are some methods for <code>*File</
each of which declares a receiver variable
<code>
file
</code>
.
each of which declares a receiver variable
<code>
file
</code>
.
<p>
<p>
<pre>
<!--{{code "progs/file.go" `/Close/` "$"}}
<pre>
<!--{{code "progs/file.go" `/Close/` "$"}}
-->
func (file *File) Close()
os.E
rror {
-->
func (file *File) Close()
e
rror {
if file == nil {
if file == nil {
return os.EINVAL
return os.EINVAL
}
}
...
@@ -634,7 +634,7 @@ each of which declares a receiver variable <code>file</code>.
...
@@ -634,7 +634,7 @@ each of which declares a receiver variable <code>file</code>.
return nil
return nil
}
}
func (file *File) Read(b []byte) (ret int, err
os.E
rror) {
func (file *File) Read(b []byte) (ret int, err
e
rror) {
if file == nil {
if file == nil {
return -1, os.EINVAL
return -1, os.EINVAL
}
}
...
@@ -645,7 +645,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
...
@@ -645,7 +645,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
return int(r), err
return int(r), err
}
}
func (file *File) Write(b []byte) (ret int, err
os.E
rror) {
func (file *File) Write(b []byte) (ret int, err
e
rror) {
if file == nil {
if file == nil {
return -1, os.EINVAL
return -1, os.EINVAL
}
}
...
@@ -690,7 +690,7 @@ func main() {
...
@@ -690,7 +690,7 @@ func main() {
file.Stdout.Write(hello)
file.Stdout.Write(hello)
f, err := file.Open(
"
/does/not/exist
"
)
f, err := file.Open(
"
/does/not/exist
"
)
if f == nil {
if f == nil {
fmt.Printf(
"
can
'
t open file; err=%s\n
"
, err.
String
())
fmt.Printf(
"
can
'
t open file; err=%s\n
"
, err.
Error
())
os.Exit(1)
os.Exit(1)
}
}
}
}
...
@@ -793,7 +793,7 @@ Here is code from <code>progs/cat_rot13.go</code>:
...
@@ -793,7 +793,7 @@ Here is code from <code>progs/cat_rot13.go</code>:
<p>
<p>
<pre>
<!--{{code "progs/cat_rot13.go" `/type.reader/` `/^}/`}}
<pre>
<!--{{code "progs/cat_rot13.go" `/type.reader/` `/^}/`}}
-->
type reader interface {
-->
type reader interface {
Read(b []byte) (ret int, err
os.E
rror)
Read(b []byte) (ret int, err
e
rror)
String() string
String() string
}
}
</pre>
</pre>
...
@@ -817,7 +817,7 @@ func newRotate13(source reader) *rotate13 {
...
@@ -817,7 +817,7 @@ func newRotate13(source reader) *rotate13 {
return
&
rotate13{source}
return
&
rotate13{source}
}
}
func (r13 *rotate13) Read(b []byte) (ret int, err
os.E
rror) {
func (r13 *rotate13) Read(b []byte) (ret int, err
e
rror) {
r, e := r13.source.Read(b)
r, e := r13.source.Read(b)
for i := 0; i
<
r; i++ {
for i := 0; i
<
r; i++ {
b[i] = rot13(b[i])
b[i] = rot13(b[i])
...
...
doc/progs/cat_rot13.go
View file @
44526cdb
...
@@ -24,7 +24,7 @@ func rot13(b byte) byte {
...
@@ -24,7 +24,7 @@ func rot13(b byte) byte {
}
}
type
reader
interface
{
type
reader
interface
{
Read
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
Read
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
String
()
string
String
()
string
}
}
...
@@ -36,7 +36,7 @@ func newRotate13(source reader) *rotate13 {
...
@@ -36,7 +36,7 @@ func newRotate13(source reader) *rotate13 {
return
&
rotate13
{
source
}
return
&
rotate13
{
source
}
}
}
func
(
r13
*
rotate13
)
Read
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
{
func
(
r13
*
rotate13
)
Read
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
{
r
,
e
:=
r13
.
source
.
Read
(
b
)
r
,
e
:=
r13
.
source
.
Read
(
b
)
for
i
:=
0
;
i
<
r
;
i
++
{
for
i
:=
0
;
i
<
r
;
i
++
{
b
[
i
]
=
rot13
(
b
[
i
])
b
[
i
]
=
rot13
(
b
[
i
])
...
...
doc/progs/file.go
View file @
44526cdb
...
@@ -27,7 +27,7 @@ var (
...
@@ -27,7 +27,7 @@ var (
Stderr
=
newFile
(
syscall
.
Stderr
,
"/dev/stderr"
)
Stderr
=
newFile
(
syscall
.
Stderr
,
"/dev/stderr"
)
)
)
func
OpenFile
(
name
string
,
mode
int
,
perm
uint32
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
OpenFile
(
name
string
,
mode
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
r
,
e
:=
syscall
.
Open
(
name
,
mode
,
perm
)
r
,
e
:=
syscall
.
Open
(
name
,
mode
,
perm
)
if
e
!=
0
{
if
e
!=
0
{
err
=
os
.
Errno
(
e
)
err
=
os
.
Errno
(
e
)
...
@@ -42,15 +42,15 @@ const (
...
@@ -42,15 +42,15 @@ const (
O_TRUNC
=
syscall
.
O_TRUNC
O_TRUNC
=
syscall
.
O_TRUNC
)
)
func
Open
(
name
string
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
Open
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDONLY
,
0
)
return
OpenFile
(
name
,
O_RDONLY
,
0
)
}
}
func
Create
(
name
string
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
Create
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
}
}
func
(
file
*
File
)
Close
()
os
.
E
rror
{
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
{
if
file
==
nil
{
return
os
.
EINVAL
return
os
.
EINVAL
}
}
...
@@ -62,7 +62,7 @@ func (file *File) Close() os.Error {
...
@@ -62,7 +62,7 @@ func (file *File) Close() os.Error {
return
nil
return
nil
}
}
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
{
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
-
1
,
os
.
EINVAL
return
-
1
,
os
.
EINVAL
}
}
...
@@ -73,7 +73,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
...
@@ -73,7 +73,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
return
int
(
r
),
err
return
int
(
r
),
err
}
}
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
{
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
-
1
,
os
.
EINVAL
return
-
1
,
os
.
EINVAL
}
}
...
...
doc/progs/file_windows.go
View file @
44526cdb
...
@@ -27,7 +27,7 @@ var (
...
@@ -27,7 +27,7 @@ var (
Stderr
=
newFile
(
syscall
.
Stderr
,
"/dev/stderr"
)
Stderr
=
newFile
(
syscall
.
Stderr
,
"/dev/stderr"
)
)
)
func
OpenFile
(
name
string
,
mode
int
,
perm
uint32
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
OpenFile
(
name
string
,
mode
int
,
perm
uint32
)
(
file
*
File
,
err
e
rror
)
{
r
,
e
:=
syscall
.
Open
(
name
,
mode
,
perm
)
r
,
e
:=
syscall
.
Open
(
name
,
mode
,
perm
)
if
e
!=
0
{
if
e
!=
0
{
err
=
os
.
Errno
(
e
)
err
=
os
.
Errno
(
e
)
...
@@ -42,15 +42,15 @@ const (
...
@@ -42,15 +42,15 @@ const (
O_TRUNC
=
syscall
.
O_TRUNC
O_TRUNC
=
syscall
.
O_TRUNC
)
)
func
Open
(
name
string
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
Open
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDONLY
,
0
)
return
OpenFile
(
name
,
O_RDONLY
,
0
)
}
}
func
Create
(
name
string
)
(
file
*
File
,
err
os
.
E
rror
)
{
func
Create
(
name
string
)
(
file
*
File
,
err
e
rror
)
{
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
return
OpenFile
(
name
,
O_RDWR
|
O_CREATE
|
O_TRUNC
,
0666
)
}
}
func
(
file
*
File
)
Close
()
os
.
E
rror
{
func
(
file
*
File
)
Close
()
e
rror
{
if
file
==
nil
{
if
file
==
nil
{
return
os
.
EINVAL
return
os
.
EINVAL
}
}
...
@@ -62,7 +62,7 @@ func (file *File) Close() os.Error {
...
@@ -62,7 +62,7 @@ func (file *File) Close() os.Error {
return
nil
return
nil
}
}
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
{
func
(
file
*
File
)
Read
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
-
1
,
os
.
EINVAL
return
-
1
,
os
.
EINVAL
}
}
...
@@ -73,7 +73,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
...
@@ -73,7 +73,7 @@ func (file *File) Read(b []byte) (ret int, err os.Error) {
return
int
(
r
),
err
return
int
(
r
),
err
}
}
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
ret
int
,
err
os
.
E
rror
)
{
func
(
file
*
File
)
Write
(
b
[]
byte
)
(
ret
int
,
err
e
rror
)
{
if
file
==
nil
{
if
file
==
nil
{
return
-
1
,
os
.
EINVAL
return
-
1
,
os
.
EINVAL
}
}
...
...
doc/progs/helloworld3.go
View file @
44526cdb
...
@@ -15,7 +15,7 @@ func main() {
...
@@ -15,7 +15,7 @@ func main() {
file
.
Stdout
.
Write
(
hello
)
file
.
Stdout
.
Write
(
hello
)
f
,
err
:=
file
.
Open
(
"/does/not/exist"
)
f
,
err
:=
file
.
Open
(
"/does/not/exist"
)
if
f
==
nil
{
if
f
==
nil
{
fmt
.
Printf
(
"can't open file; err=%s
\n
"
,
err
.
String
())
fmt
.
Printf
(
"can't open file; err=%s
\n
"
,
err
.
Error
())
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
}
}
doc/talks/io2010/decrypt.go
View file @
44526cdb
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
"os"
"os"
)
)
func
EncryptAndGzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
os
.
E
rror
{
func
EncryptAndGzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
e
rror
{
r
,
err
:=
os
.
Open
(
srcfile
)
r
,
err
:=
os
.
Open
(
srcfile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -39,7 +39,7 @@ func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) os.Error {
...
@@ -39,7 +39,7 @@ func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) os.Error {
return
err
return
err
}
}
func
DecryptAndGunzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
os
.
E
rror
{
func
DecryptAndGunzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
e
rror
{
f
,
err
:=
os
.
Open
(
srcfile
)
f
,
err
:=
os
.
Open
(
srcfile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
doc/talks/io2010/encrypt.go
View file @
44526cdb
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
"os"
"os"
)
)
func
EncryptAndGzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
os
.
E
rror
{
func
EncryptAndGzip
(
dstfile
,
srcfile
string
,
key
,
iv
[]
byte
)
e
rror
{
r
,
err
:=
os
.
Open
(
srcfile
)
r
,
err
:=
os
.
Open
(
srcfile
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
doc/tmpltohtml.go
View file @
44526cdb
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
// The template uses the function "code" to inject program
// The template uses the function "code" to inject program
// source into the output by extracting code from files and
// source into the output by extracting code from files and
// injecting them as HTML-escaped <pre> blocks.
// injecting them as HTML-escaped <pre> blocks.
...
@@ -81,7 +80,7 @@ func format(arg interface{}) string {
...
@@ -81,7 +80,7 @@ func format(arg interface{}) string {
return
""
return
""
}
}
func
code
(
file
string
,
arg
...
interface
{})
(
string
,
os
.
E
rror
)
{
func
code
(
file
string
,
arg
...
interface
{})
(
string
,
e
rror
)
{
text
:=
contents
(
file
)
text
:=
contents
(
file
)
var
command
string
var
command
string
switch
len
(
arg
)
{
switch
len
(
arg
)
{
...
...
misc/cgo/gmp/gmp.go
View file @
44526cdb
...
@@ -179,7 +179,7 @@ func (z *Int) SetInt64(x int64) *Int {
...
@@ -179,7 +179,7 @@ func (z *Int) SetInt64(x int64) *Int {
// SetString interprets s as a number in the given base
// SetString interprets s as a number in the given base
// and sets z to that value. The base must be in the range [2,36].
// and sets z to that value. The base must be in the range [2,36].
// SetString returns an error if s cannot be parsed or the base is invalid.
// SetString returns an error if s cannot be parsed or the base is invalid.
func
(
z
*
Int
)
SetString
(
s
string
,
base
int
)
os
.
E
rror
{
func
(
z
*
Int
)
SetString
(
s
string
,
base
int
)
e
rror
{
z
.
doinit
()
z
.
doinit
()
if
base
<
2
||
base
>
36
{
if
base
<
2
||
base
>
36
{
return
os
.
EINVAL
return
os
.
EINVAL
...
...
misc/cgo/test/basic.go
View file @
44526cdb
...
@@ -69,7 +69,7 @@ func uuidgen() {
...
@@ -69,7 +69,7 @@ func uuidgen() {
C
.
uuid_generate
(
&
uuid
[
0
])
C
.
uuid_generate
(
&
uuid
[
0
])
}
}
func
Size
(
name
string
)
(
int64
,
os
.
E
rror
)
{
func
Size
(
name
string
)
(
int64
,
e
rror
)
{
var
st
C
.
struct_stat
var
st
C
.
struct_stat
p
:=
C
.
CString
(
name
)
p
:=
C
.
CString
(
name
)
_
,
err
:=
C
.
stat
(
p
,
&
st
)
_
,
err
:=
C
.
stat
(
p
,
&
st
)
...
@@ -80,7 +80,7 @@ func Size(name string) (int64, os.Error) {
...
@@ -80,7 +80,7 @@ func Size(name string) (int64, os.Error) {
return
int64
(
C
.
ulong
(
st
.
st_size
)),
nil
return
int64
(
C
.
ulong
(
st
.
st_size
)),
nil
}
}
func
Strtol
(
s
string
,
base
int
)
(
int
,
os
.
E
rror
)
{
func
Strtol
(
s
string
,
base
int
)
(
int
,
e
rror
)
{
p
:=
C
.
CString
(
s
)
p
:=
C
.
CString
(
s
)
n
,
err
:=
C
.
strtol
(
p
,
nil
,
C
.
int
(
base
))
n
,
err
:=
C
.
strtol
(
p
,
nil
,
C
.
int
(
base
))
C
.
free
(
unsafe
.
Pointer
(
p
))
C
.
free
(
unsafe
.
Pointer
(
p
))
...
...
misc/dashboard/builder/exec.go
View file @
44526cdb
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
)
)
// run is a simple wrapper for exec.Run/Close
// run is a simple wrapper for exec.Run/Close
func
run
(
envv
[]
string
,
dir
string
,
argv
...
string
)
os
.
E
rror
{
func
run
(
envv
[]
string
,
dir
string
,
argv
...
string
)
e
rror
{
if
*
verbose
{
if
*
verbose
{
log
.
Println
(
"run"
,
argv
)
log
.
Println
(
"run"
,
argv
)
}
}
...
@@ -31,7 +31,7 @@ func run(envv []string, dir string, argv ...string) os.Error {
...
@@ -31,7 +31,7 @@ func run(envv []string, dir string, argv ...string) os.Error {
// process combined stdout and stderr output, exit status and error.
// process combined stdout and stderr output, exit status and error.
// The error returned is nil, if process is started successfully,
// The error returned is nil, if process is started successfully,
// even if exit status is not 0.
// even if exit status is not 0.
func
runLog
(
envv
[]
string
,
logfile
,
dir
string
,
argv
...
string
)
(
string
,
int
,
os
.
E
rror
)
{
func
runLog
(
envv
[]
string
,
logfile
,
dir
string
,
argv
...
string
)
(
string
,
int
,
e
rror
)
{
if
*
verbose
{
if
*
verbose
{
log
.
Println
(
"runLog"
,
argv
)
log
.
Println
(
"runLog"
,
argv
)
}
}
...
@@ -56,7 +56,7 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, os
...
@@ -56,7 +56,7 @@ func runLog(envv []string, logfile, dir string, argv ...string) (string, int, os
err
:=
cmd
.
Run
()
err
:=
cmd
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
if
ws
,
ok
:=
err
.
(
*
os
.
Waitmsg
);
ok
{
if
ws
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
return
b
.
String
(),
ws
.
ExitStatus
(),
nil
return
b
.
String
(),
ws
.
ExitStatus
(),
nil
}
}
}
}
...
...
misc/dashboard/builder/http.go
View file @
44526cdb
...
@@ -6,11 +6,11 @@ package main
...
@@ -6,11 +6,11 @@ package main
import
(
import
(
"bytes"
"bytes"
"errors"
"fmt"
"fmt"
"http"
"http"
"json"
"json"
"log"
"log"
"os"
"strconv"
"strconv"
"url"
"url"
)
)
...
@@ -20,9 +20,9 @@ type param map[string]string
...
@@ -20,9 +20,9 @@ type param map[string]string
// dash runs the given method and command on the dashboard.
// dash runs the given method and command on the dashboard.
// If args is not nil, it is the query or post parameters.
// If args is not nil, it is the query or post parameters.
// If resp is not nil, dash unmarshals the body as JSON into resp.
// If resp is not nil, dash unmarshals the body as JSON into resp.
func
dash
(
meth
,
cmd
string
,
resp
interface
{},
args
param
)
os
.
E
rror
{
func
dash
(
meth
,
cmd
string
,
resp
interface
{},
args
param
)
e
rror
{
var
r
*
http
.
Response
var
r
*
http
.
Response
var
err
os
.
E
rror
var
err
e
rror
if
*
verbose
{
if
*
verbose
{
log
.
Println
(
"dash"
,
cmd
,
args
)
log
.
Println
(
"dash"
,
cmd
,
args
)
}
}
...
@@ -57,7 +57,7 @@ func dash(meth, cmd string, resp interface{}, args param) os.Error {
...
@@ -57,7 +57,7 @@ func dash(meth, cmd string, resp interface{}, args param) os.Error {
return
nil
return
nil
}
}
func
dashStatus
(
meth
,
cmd
string
,
args
param
)
os
.
E
rror
{
func
dashStatus
(
meth
,
cmd
string
,
args
param
)
e
rror
{
var
resp
struct
{
var
resp
struct
{
Status
string
Status
string
Error
string
Error
string
...
@@ -67,13 +67,13 @@ func dashStatus(meth, cmd string, args param) os.Error {
...
@@ -67,13 +67,13 @@ func dashStatus(meth, cmd string, args param) os.Error {
return
err
return
err
}
}
if
resp
.
Status
!=
"OK"
{
if
resp
.
Status
!=
"OK"
{
return
os
.
NewError
(
"/build: "
+
resp
.
Error
)
return
errors
.
New
(
"/build: "
+
resp
.
Error
)
}
}
return
nil
return
nil
}
}
// todo returns the next hash to build.
// todo returns the next hash to build.
func
(
b
*
Builder
)
todo
()
(
rev
string
,
err
os
.
E
rror
)
{
func
(
b
*
Builder
)
todo
()
(
rev
string
,
err
e
rror
)
{
var
resp
[]
struct
{
var
resp
[]
struct
{
Hash
string
Hash
string
}
}
...
@@ -87,7 +87,7 @@ func (b *Builder) todo() (rev string, err os.Error) {
...
@@ -87,7 +87,7 @@ func (b *Builder) todo() (rev string, err os.Error) {
}
}
// recordResult sends build results to the dashboard
// recordResult sends build results to the dashboard
func
(
b
*
Builder
)
recordResult
(
buildLog
string
,
hash
string
)
os
.
E
rror
{
func
(
b
*
Builder
)
recordResult
(
buildLog
string
,
hash
string
)
e
rror
{
return
dash
(
"POST"
,
"build"
,
nil
,
param
{
return
dash
(
"POST"
,
"build"
,
nil
,
param
{
"builder"
:
b
.
name
,
"builder"
:
b
.
name
,
"key"
:
b
.
key
,
"key"
:
b
.
key
,
...
@@ -97,7 +97,7 @@ func (b *Builder) recordResult(buildLog string, hash string) os.Error {
...
@@ -97,7 +97,7 @@ func (b *Builder) recordResult(buildLog string, hash string) os.Error {
}
}
// packages fetches a list of package paths from the dashboard
// packages fetches a list of package paths from the dashboard
func
packages
()
(
pkgs
[]
string
,
err
os
.
E
rror
)
{
func
packages
()
(
pkgs
[]
string
,
err
e
rror
)
{
var
resp
struct
{
var
resp
struct
{
Packages
[]
struct
{
Packages
[]
struct
{
Path
string
Path
string
...
@@ -114,7 +114,7 @@ func packages() (pkgs []string, err os.Error) {
...
@@ -114,7 +114,7 @@ func packages() (pkgs []string, err os.Error) {
}
}
// updatePackage sends package build results and info dashboard
// updatePackage sends package build results and info dashboard
func
(
b
*
Builder
)
updatePackage
(
pkg
string
,
ok
bool
,
buildLog
,
info
string
)
os
.
E
rror
{
func
(
b
*
Builder
)
updatePackage
(
pkg
string
,
ok
bool
,
buildLog
,
info
string
)
e
rror
{
return
dash
(
"POST"
,
"package"
,
nil
,
param
{
return
dash
(
"POST"
,
"package"
,
nil
,
param
{
"builder"
:
b
.
name
,
"builder"
:
b
.
name
,
"key"
:
b
.
key
,
"key"
:
b
.
key
,
...
@@ -126,7 +126,7 @@ func (b *Builder) updatePackage(pkg string, ok bool, buildLog, info string) os.E
...
@@ -126,7 +126,7 @@ func (b *Builder) updatePackage(pkg string, ok bool, buildLog, info string) os.E
}
}
// postCommit informs the dashboard of a new commit
// postCommit informs the dashboard of a new commit
func
postCommit
(
key
string
,
l
*
HgLog
)
os
.
E
rror
{
func
postCommit
(
key
string
,
l
*
HgLog
)
e
rror
{
return
dashStatus
(
"POST"
,
"commit"
,
param
{
return
dashStatus
(
"POST"
,
"commit"
,
param
{
"key"
:
key
,
"key"
:
key
,
"node"
:
l
.
Hash
,
"node"
:
l
.
Hash
,
...
...
misc/dashboard/builder/main.go
View file @
44526cdb
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
main
package
main
import
(
import
(
"errors"
"flag"
"flag"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
...
@@ -158,7 +159,7 @@ func main() {
...
@@ -158,7 +159,7 @@ func main() {
}
}
}
}
func
NewBuilder
(
builder
string
)
(
*
Builder
,
os
.
E
rror
)
{
func
NewBuilder
(
builder
string
)
(
*
Builder
,
e
rror
)
{
b
:=
&
Builder
{
name
:
builder
}
b
:=
&
Builder
{
name
:
builder
}
// get goos/goarch from builder string
// get goos/goarch from builder string
...
@@ -259,7 +260,7 @@ func (b *Builder) build() bool {
...
@@ -259,7 +260,7 @@ func (b *Builder) build() bool {
return
true
return
true
}
}
func
(
b
*
Builder
)
buildHash
(
hash
string
)
(
err
os
.
E
rror
)
{
func
(
b
*
Builder
)
buildHash
(
hash
string
)
(
err
e
rror
)
{
defer
func
()
{
defer
func
()
{
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"%s build: %s: %s"
,
b
.
name
,
hash
,
err
)
err
=
fmt
.
Errorf
(
"%s build: %s: %s"
,
b
.
name
,
hash
,
err
)
...
@@ -301,7 +302,7 @@ func (b *Builder) buildHash(hash string) (err os.Error) {
...
@@ -301,7 +302,7 @@ func (b *Builder) buildHash(hash string) (err os.Error) {
// if we're in external mode, build all packages and return
// if we're in external mode, build all packages and return
if
*
external
{
if
*
external
{
if
status
!=
0
{
if
status
!=
0
{
return
os
.
NewError
(
"go build failed"
)
return
errors
.
New
(
"go build failed"
)
}
}
return
b
.
buildPackages
(
workpath
,
hash
)
return
b
.
buildPackages
(
workpath
,
hash
)
}
}
...
@@ -572,7 +573,7 @@ func addCommit(hash, key string) bool {
...
@@ -572,7 +573,7 @@ func addCommit(hash, key string) bool {
}
}
// fullHash returns the full hash for the given Mercurial revision.
// fullHash returns the full hash for the given Mercurial revision.
func
fullHash
(
rev
string
)
(
hash
string
,
err
os
.
E
rror
)
{
func
fullHash
(
rev
string
)
(
hash
string
,
err
e
rror
)
{
defer
func
()
{
defer
func
()
{
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"fullHash: %s: %s"
,
rev
,
err
)
err
=
fmt
.
Errorf
(
"fullHash: %s: %s"
,
rev
,
err
)
...
@@ -601,7 +602,7 @@ func fullHash(rev string) (hash string, err os.Error) {
...
@@ -601,7 +602,7 @@ func fullHash(rev string) (hash string, err os.Error) {
var
revisionRe
=
regexp
.
MustCompile
(
`^([^ ]+) +[0-9]+:([0-9a-f]+)$`
)
var
revisionRe
=
regexp
.
MustCompile
(
`^([^ ]+) +[0-9]+:([0-9a-f]+)$`
)
// firstTag returns the hash and tag of the most recent tag matching re.
// firstTag returns the hash and tag of the most recent tag matching re.
func
firstTag
(
re
*
regexp
.
Regexp
)
(
hash
string
,
tag
string
,
err
os
.
E
rror
)
{
func
firstTag
(
re
*
regexp
.
Regexp
)
(
hash
string
,
tag
string
,
err
e
rror
)
{
o
,
_
,
err
:=
runLog
(
nil
,
""
,
goroot
,
"hg"
,
"tags"
)
o
,
_
,
err
:=
runLog
(
nil
,
""
,
goroot
,
"hg"
,
"tags"
)
for
_
,
l
:=
range
strings
.
Split
(
o
,
"
\n
"
)
{
for
_
,
l
:=
range
strings
.
Split
(
o
,
"
\n
"
)
{
if
l
==
""
{
if
l
==
""
{
...
@@ -609,7 +610,7 @@ func firstTag(re *regexp.Regexp) (hash string, tag string, err os.Error) {
...
@@ -609,7 +610,7 @@ func firstTag(re *regexp.Regexp) (hash string, tag string, err os.Error) {
}
}
s
:=
revisionRe
.
FindStringSubmatch
(
l
)
s
:=
revisionRe
.
FindStringSubmatch
(
l
)
if
s
==
nil
{
if
s
==
nil
{
err
=
os
.
NewError
(
"couldn't find revision number"
)
err
=
errors
.
New
(
"couldn't find revision number"
)
return
return
}
}
if
!
re
.
MatchString
(
s
[
1
])
{
if
!
re
.
MatchString
(
s
[
1
])
{
...
@@ -619,6 +620,6 @@ func firstTag(re *regexp.Regexp) (hash string, tag string, err os.Error) {
...
@@ -619,6 +620,6 @@ func firstTag(re *regexp.Regexp) (hash string, tag string, err os.Error) {
hash
,
err
=
fullHash
(
s
[
2
])
hash
,
err
=
fullHash
(
s
[
2
])
return
return
}
}
err
=
os
.
NewError
(
"no matching tag found"
)
err
=
errors
.
New
(
"no matching tag found"
)
return
return
}
}
misc/dashboard/builder/package.go
View file @
44526cdb
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
package
main
package
main
import
(
import
(
"errors"
"fmt"
"fmt"
"go/doc"
"go/doc"
"go/parser"
"go/parser"
...
@@ -17,7 +18,7 @@ import (
...
@@ -17,7 +18,7 @@ import (
const
MaxCommentLength
=
500
// App Engine won't store more in a StringProperty.
const
MaxCommentLength
=
500
// App Engine won't store more in a StringProperty.
func
(
b
*
Builder
)
buildPackages
(
workpath
string
,
hash
string
)
os
.
E
rror
{
func
(
b
*
Builder
)
buildPackages
(
workpath
string
,
hash
string
)
e
rror
{
logdir
:=
filepath
.
Join
(
*
buildroot
,
"log"
)
logdir
:=
filepath
.
Join
(
*
buildroot
,
"log"
)
if
err
:=
os
.
Mkdir
(
logdir
,
0755
);
err
!=
nil
{
if
err
:=
os
.
Mkdir
(
logdir
,
0755
);
err
!=
nil
{
return
err
return
err
...
@@ -87,7 +88,7 @@ func isGoFile(fi *os.FileInfo) bool {
...
@@ -87,7 +88,7 @@ func isGoFile(fi *os.FileInfo) bool {
filepath
.
Ext
(
fi
.
Name
)
==
".go"
filepath
.
Ext
(
fi
.
Name
)
==
".go"
}
}
func
packageComment
(
pkg
,
pkgpath
string
)
(
info
string
,
err
os
.
E
rror
)
{
func
packageComment
(
pkg
,
pkgpath
string
)
(
info
string
,
err
e
rror
)
{
fset
:=
token
.
NewFileSet
()
fset
:=
token
.
NewFileSet
()
pkgs
,
err
:=
parser
.
ParseDir
(
fset
,
pkgpath
,
isGoFile
,
parser
.
PackageClauseOnly
|
parser
.
ParseComments
)
pkgs
,
err
:=
parser
.
ParseDir
(
fset
,
pkgpath
,
isGoFile
,
parser
.
PackageClauseOnly
|
parser
.
ParseComments
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -102,7 +103,7 @@ func packageComment(pkg, pkgpath string) (info string, err os.Error) {
...
@@ -102,7 +103,7 @@ func packageComment(pkg, pkgpath string) (info string, err os.Error) {
continue
continue
}
}
if
info
!=
""
{
if
info
!=
""
{
return
""
,
os
.
NewError
(
"multiple packages with docs"
)
return
""
,
errors
.
New
(
"multiple packages with docs"
)
}
}
info
=
pdoc
.
Doc
info
=
pdoc
.
Doc
}
}
...
...
misc/goplay/goplay.go
View file @
44526cdb
...
@@ -84,14 +84,14 @@ func Compile(w http.ResponseWriter, req *http.Request) {
...
@@ -84,14 +84,14 @@ func Compile(w http.ResponseWriter, req *http.Request) {
// write request Body to x.go
// write request Body to x.go
f
,
err
:=
os
.
Create
(
src
)
f
,
err
:=
os
.
Create
(
src
)
if
err
!=
nil
{
if
err
!=
nil
{
error
(
w
,
nil
,
err
)
error
_
(
w
,
nil
,
err
)
return
return
}
}
defer
os
.
Remove
(
src
)
defer
os
.
Remove
(
src
)
defer
f
.
Close
()
defer
f
.
Close
()
_
,
err
=
io
.
Copy
(
f
,
req
.
Body
)
_
,
err
=
io
.
Copy
(
f
,
req
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
error
(
w
,
nil
,
err
)
error
_
(
w
,
nil
,
err
)
return
return
}
}
f
.
Close
()
f
.
Close
()
...
@@ -100,7 +100,7 @@ func Compile(w http.ResponseWriter, req *http.Request) {
...
@@ -100,7 +100,7 @@ func Compile(w http.ResponseWriter, req *http.Request) {
out
,
err
:=
run
(
archChar
+
"g"
,
"-o"
,
obj
,
src
)
out
,
err
:=
run
(
archChar
+
"g"
,
"-o"
,
obj
,
src
)
defer
os
.
Remove
(
obj
)
defer
os
.
Remove
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
error
(
w
,
out
,
err
)
error
_
(
w
,
out
,
err
)
return
return
}
}
...
@@ -108,14 +108,14 @@ func Compile(w http.ResponseWriter, req *http.Request) {
...
@@ -108,14 +108,14 @@ func Compile(w http.ResponseWriter, req *http.Request) {
out
,
err
=
run
(
archChar
+
"l"
,
"-o"
,
bin
,
obj
)
out
,
err
=
run
(
archChar
+
"l"
,
"-o"
,
bin
,
obj
)
defer
os
.
Remove
(
bin
)
defer
os
.
Remove
(
bin
)
if
err
!=
nil
{
if
err
!=
nil
{
error
(
w
,
out
,
err
)
error
_
(
w
,
out
,
err
)
return
return
}
}
// run x
// run x
out
,
err
=
run
(
bin
)
out
,
err
=
run
(
bin
)
if
err
!=
nil
{
if
err
!=
nil
{
error
(
w
,
out
,
err
)
error
_
(
w
,
out
,
err
)
}
}
// write the output of x as the http response
// write the output of x as the http response
...
@@ -128,17 +128,17 @@ func Compile(w http.ResponseWriter, req *http.Request) {
...
@@ -128,17 +128,17 @@ func Compile(w http.ResponseWriter, req *http.Request) {
// error writes compile, link, or runtime errors to the HTTP connection.
// error writes compile, link, or runtime errors to the HTTP connection.
// The JavaScript interface uses the 404 status code to identify the error.
// The JavaScript interface uses the 404 status code to identify the error.
func
error
(
w
http
.
ResponseWriter
,
out
[]
byte
,
err
os
.
E
rror
)
{
func
error
_
(
w
http
.
ResponseWriter
,
out
[]
byte
,
err
e
rror
)
{
w
.
WriteHeader
(
404
)
w
.
WriteHeader
(
404
)
if
out
!=
nil
{
if
out
!=
nil
{
output
.
Execute
(
w
,
out
)
output
.
Execute
(
w
,
out
)
}
else
{
}
else
{
output
.
Execute
(
w
,
err
.
String
())
output
.
Execute
(
w
,
err
.
Error
())
}
}
}
}
// run executes the specified command and returns its output and an error.
// run executes the specified command and returns its output and an error.
func
run
(
cmd
...
string
)
([]
byte
,
os
.
E
rror
)
{
func
run
(
cmd
...
string
)
([]
byte
,
e
rror
)
{
return
exec
.
Command
(
cmd
[
0
],
cmd
[
1
:
]
...
)
.
CombinedOutput
()
return
exec
.
Command
(
cmd
[
0
],
cmd
[
1
:
]
...
)
.
CombinedOutput
()
}
}
...
...
src/cmd/cgo/ast.go
View file @
44526cdb
...
@@ -71,7 +71,7 @@ func (f *File) ReadGo(name string) {
...
@@ -71,7 +71,7 @@ func (f *File) ReadGo(name string) {
}
}
sawC
=
true
sawC
=
true
if
s
.
Name
!=
nil
{
if
s
.
Name
!=
nil
{
error
(
s
.
Path
.
Pos
(),
`cannot rename import "C"`
)
error
_
(
s
.
Path
.
Pos
(),
`cannot rename import "C"`
)
}
}
cg
:=
s
.
Doc
cg
:=
s
.
Doc
if
cg
==
nil
&&
len
(
d
.
Specs
)
==
1
{
if
cg
==
nil
&&
len
(
d
.
Specs
)
==
1
{
...
@@ -84,7 +84,7 @@ func (f *File) ReadGo(name string) {
...
@@ -84,7 +84,7 @@ func (f *File) ReadGo(name string) {
}
}
}
}
if
!
sawC
{
if
!
sawC
{
error
(
token
.
NoPos
,
`cannot find import "C"`
)
error
_
(
token
.
NoPos
,
`cannot find import "C"`
)
}
}
// In ast2, strip the import "C" line.
// In ast2, strip the import "C" line.
...
@@ -149,7 +149,7 @@ func (f *File) saveRef(x interface{}, context string) {
...
@@ -149,7 +149,7 @@ func (f *File) saveRef(x interface{}, context string) {
}
}
goname
:=
sel
.
Sel
.
Name
goname
:=
sel
.
Sel
.
Name
if
goname
==
"errno"
{
if
goname
==
"errno"
{
error
(
sel
.
Pos
(),
"cannot refer to errno directly; see documentation"
)
error
_
(
sel
.
Pos
(),
"cannot refer to errno directly; see documentation"
)
return
return
}
}
name
:=
f
.
Name
[
goname
]
name
:=
f
.
Name
[
goname
]
...
@@ -186,11 +186,11 @@ func (f *File) saveExport(x interface{}, context string) {
...
@@ -186,11 +186,11 @@ func (f *File) saveExport(x interface{}, context string) {
name
:=
strings
.
TrimSpace
(
string
(
c
.
Text
[
9
:
]))
name
:=
strings
.
TrimSpace
(
string
(
c
.
Text
[
9
:
]))
if
name
==
""
{
if
name
==
""
{
error
(
c
.
Pos
(),
"export missing name"
)
error
_
(
c
.
Pos
(),
"export missing name"
)
}
}
if
name
!=
n
.
Name
.
Name
{
if
name
!=
n
.
Name
.
Name
{
error
(
c
.
Pos
(),
"export comment has wrong name %q, want %q"
,
name
,
n
.
Name
.
Name
)
error
_
(
c
.
Pos
(),
"export comment has wrong name %q, want %q"
,
name
,
n
.
Name
.
Name
)
}
}
f
.
ExpFunc
=
append
(
f
.
ExpFunc
,
&
ExpFunc
{
f
.
ExpFunc
=
append
(
f
.
ExpFunc
,
&
ExpFunc
{
...
@@ -225,7 +225,7 @@ func (f *File) walk(x interface{}, context string, visit func(*File, interface{}
...
@@ -225,7 +225,7 @@ func (f *File) walk(x interface{}, context string, visit func(*File, interface{}
// everything else just recurs
// everything else just recurs
default
:
default
:
error
(
token
.
NoPos
,
"unexpected type %T in walk"
,
x
,
visit
)
error
_
(
token
.
NoPos
,
"unexpected type %T in walk"
,
x
,
visit
)
panic
(
"unexpected type"
)
panic
(
"unexpected type"
)
case
nil
:
case
nil
:
...
...
src/cmd/cgo/gcc.go
View file @
44526cdb
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"debug/macho"
"debug/macho"
"debug/pe"
"debug/pe"
"encoding/binary"
"encoding/binary"
"errors"
"flag"
"flag"
"fmt"
"fmt"
"go/ast"
"go/ast"
...
@@ -147,10 +148,10 @@ func (p *Package) addToFlag(flag string, args []string) {
...
@@ -147,10 +148,10 @@ func (p *Package) addToFlag(flag string, args []string) {
// pkgConfig runs pkg-config and extracts --libs and --cflags information
// pkgConfig runs pkg-config and extracts --libs and --cflags information
// for packages.
// for packages.
func
pkgConfig
(
packages
[]
string
)
(
cflags
,
ldflags
[]
string
,
err
os
.
E
rror
)
{
func
pkgConfig
(
packages
[]
string
)
(
cflags
,
ldflags
[]
string
,
err
e
rror
)
{
for
_
,
name
:=
range
packages
{
for
_
,
name
:=
range
packages
{
if
len
(
name
)
==
0
||
name
[
0
]
==
'-'
{
if
len
(
name
)
==
0
||
name
[
0
]
==
'-'
{
return
nil
,
nil
,
os
.
NewError
(
fmt
.
Sprintf
(
"invalid name: %q"
,
name
))
return
nil
,
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"invalid name: %q"
,
name
))
}
}
}
}
...
@@ -158,7 +159,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
...
@@ -158,7 +159,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
stdout
,
stderr
,
ok
:=
run
(
nil
,
args
)
stdout
,
stderr
,
ok
:=
run
(
nil
,
args
)
if
!
ok
{
if
!
ok
{
os
.
Stderr
.
Write
(
stderr
)
os
.
Stderr
.
Write
(
stderr
)
return
nil
,
nil
,
os
.
NewError
(
"pkg-config failed"
)
return
nil
,
nil
,
errors
.
New
(
"pkg-config failed"
)
}
}
cflags
,
err
=
splitQuoted
(
string
(
stdout
))
cflags
,
err
=
splitQuoted
(
string
(
stdout
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -169,7 +170,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
...
@@ -169,7 +170,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
stdout
,
stderr
,
ok
=
run
(
nil
,
args
)
stdout
,
stderr
,
ok
=
run
(
nil
,
args
)
if
!
ok
{
if
!
ok
{
os
.
Stderr
.
Write
(
stderr
)
os
.
Stderr
.
Write
(
stderr
)
return
nil
,
nil
,
os
.
NewError
(
"pkg-config failed"
)
return
nil
,
nil
,
errors
.
New
(
"pkg-config failed"
)
}
}
ldflags
,
err
=
splitQuoted
(
string
(
stdout
))
ldflags
,
err
=
splitQuoted
(
string
(
stdout
))
return
return
...
@@ -191,7 +192,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
...
@@ -191,7 +192,7 @@ func pkgConfig(packages []string) (cflags, ldflags []string, err os.Error) {
//
//
// []string{"a", "b:c d", "ef", `g"`}
// []string{"a", "b:c d", "ef", `g"`}
//
//
func
splitQuoted
(
s
string
)
(
r
[]
string
,
err
os
.
E
rror
)
{
func
splitQuoted
(
s
string
)
(
r
[]
string
,
err
e
rror
)
{
var
args
[]
string
var
args
[]
string
arg
:=
make
([]
rune
,
len
(
s
))
arg
:=
make
([]
rune
,
len
(
s
))
escaped
:=
false
escaped
:=
false
...
@@ -229,9 +230,9 @@ func splitQuoted(s string) (r []string, err os.Error) {
...
@@ -229,9 +230,9 @@ func splitQuoted(s string) (r []string, err os.Error) {
args
=
append
(
args
,
string
(
arg
[
:
i
]))
args
=
append
(
args
,
string
(
arg
[
:
i
]))
}
}
if
quote
!=
0
{
if
quote
!=
0
{
err
=
os
.
NewError
(
"unclosed quote"
)
err
=
errors
.
New
(
"unclosed quote"
)
}
else
if
escaped
{
}
else
if
escaped
{
err
=
os
.
NewError
(
"unfinished escaping"
)
err
=
errors
.
New
(
"unfinished escaping"
)
}
}
return
args
,
err
return
args
,
err
}
}
...
@@ -420,7 +421,7 @@ func (p *Package) guessKinds(f *File) []*Name {
...
@@ -420,7 +421,7 @@ func (p *Package) guessKinds(f *File) []*Name {
case
strings
.
Contains
(
line
,
": statement with no effect"
)
:
case
strings
.
Contains
(
line
,
": statement with no effect"
)
:
what
=
"not-type"
// const or func or var
what
=
"not-type"
// const or func or var
case
strings
.
Contains
(
line
,
"undeclared"
)
:
case
strings
.
Contains
(
line
,
"undeclared"
)
:
error
(
token
.
NoPos
,
"%s"
,
strings
.
TrimSpace
(
line
[
colon
+
1
:
]))
error
_
(
token
.
NoPos
,
"%s"
,
strings
.
TrimSpace
(
line
[
colon
+
1
:
]))
case
strings
.
Contains
(
line
,
"is not an integer constant"
)
:
case
strings
.
Contains
(
line
,
"is not an integer constant"
)
:
isConst
[
i
]
=
false
isConst
[
i
]
=
false
continue
continue
...
@@ -448,7 +449,7 @@ func (p *Package) guessKinds(f *File) []*Name {
...
@@ -448,7 +449,7 @@ func (p *Package) guessKinds(f *File) []*Name {
if
n
.
Kind
!=
""
{
if
n
.
Kind
!=
""
{
continue
continue
}
}
error
(
token
.
NoPos
,
"could not determine kind of name for C.%s"
,
n
.
Go
)
error
_
(
token
.
NoPos
,
"could not determine kind of name for C.%s"
,
n
.
Go
)
}
}
if
nerrors
>
0
{
if
nerrors
>
0
{
fatalf
(
"unresolved names"
)
fatalf
(
"unresolved names"
)
...
@@ -617,7 +618,7 @@ func (p *Package) rewriteRef(f *File) {
...
@@ -617,7 +618,7 @@ func (p *Package) rewriteRef(f *File) {
// functions are only used in calls.
// functions are only used in calls.
for
_
,
r
:=
range
f
.
Ref
{
for
_
,
r
:=
range
f
.
Ref
{
if
r
.
Name
.
Kind
==
"const"
&&
r
.
Name
.
Const
==
""
{
if
r
.
Name
.
Kind
==
"const"
&&
r
.
Name
.
Const
==
""
{
error
(
r
.
Pos
(),
"unable to find value of constant C.%s"
,
r
.
Name
.
Go
)
error
_
(
r
.
Pos
(),
"unable to find value of constant C.%s"
,
r
.
Name
.
Go
)
}
}
var
expr
ast
.
Expr
=
ast
.
NewIdent
(
r
.
Name
.
Mangle
)
// default
var
expr
ast
.
Expr
=
ast
.
NewIdent
(
r
.
Name
.
Mangle
)
// default
switch
r
.
Context
{
switch
r
.
Context
{
...
@@ -628,12 +629,12 @@ func (p *Package) rewriteRef(f *File) {
...
@@ -628,12 +629,12 @@ func (p *Package) rewriteRef(f *File) {
expr
=
r
.
Name
.
Type
.
Go
expr
=
r
.
Name
.
Type
.
Go
break
break
}
}
error
(
r
.
Pos
(),
"call of non-function C.%s"
,
r
.
Name
.
Go
)
error
_
(
r
.
Pos
(),
"call of non-function C.%s"
,
r
.
Name
.
Go
)
break
break
}
}
if
r
.
Context
==
"call2"
{
if
r
.
Context
==
"call2"
{
if
r
.
Name
.
FuncType
.
Result
==
nil
{
if
r
.
Name
.
FuncType
.
Result
==
nil
{
error
(
r
.
Pos
(),
"assignment count mismatch: 2 = 0"
)
error
_
(
r
.
Pos
(),
"assignment count mismatch: 2 = 0"
)
}
}
// Invent new Name for the two-result function.
// Invent new Name for the two-result function.
n
:=
f
.
Name
[
"2"
+
r
.
Name
.
Go
]
n
:=
f
.
Name
[
"2"
+
r
.
Name
.
Go
]
...
@@ -650,7 +651,7 @@ func (p *Package) rewriteRef(f *File) {
...
@@ -650,7 +651,7 @@ func (p *Package) rewriteRef(f *File) {
}
}
case
"expr"
:
case
"expr"
:
if
r
.
Name
.
Kind
==
"func"
{
if
r
.
Name
.
Kind
==
"func"
{
error
(
r
.
Pos
(),
"must call C.%s"
,
r
.
Name
.
Go
)
error
_
(
r
.
Pos
(),
"must call C.%s"
,
r
.
Name
.
Go
)
}
}
if
r
.
Name
.
Kind
==
"type"
{
if
r
.
Name
.
Kind
==
"type"
{
// Okay - might be new(T)
// Okay - might be new(T)
...
@@ -662,13 +663,13 @@ func (p *Package) rewriteRef(f *File) {
...
@@ -662,13 +663,13 @@ func (p *Package) rewriteRef(f *File) {
case
"type"
:
case
"type"
:
if
r
.
Name
.
Kind
!=
"type"
{
if
r
.
Name
.
Kind
!=
"type"
{
error
(
r
.
Pos
(),
"expression C.%s used as type"
,
r
.
Name
.
Go
)
error
_
(
r
.
Pos
(),
"expression C.%s used as type"
,
r
.
Name
.
Go
)
}
else
{
}
else
{
expr
=
r
.
Name
.
Type
.
Go
expr
=
r
.
Name
.
Type
.
Go
}
}
default
:
default
:
if
r
.
Name
.
Kind
==
"func"
{
if
r
.
Name
.
Kind
==
"func"
{
error
(
r
.
Pos
(),
"must call C.%s"
,
r
.
Name
.
Go
)
error
_
(
r
.
Pos
(),
"must call C.%s"
,
r
.
Name
.
Go
)
}
}
}
}
*
r
.
Expr
=
expr
*
r
.
Expr
=
expr
...
...
src/cmd/cgo/main.go
View file @
44526cdb
...
@@ -255,7 +255,7 @@ func (p *Package) Record(f *File) {
...
@@ -255,7 +255,7 @@ func (p *Package) Record(f *File) {
if
p
.
PackageName
==
""
{
if
p
.
PackageName
==
""
{
p
.
PackageName
=
f
.
Package
p
.
PackageName
=
f
.
Package
}
else
if
p
.
PackageName
!=
f
.
Package
{
}
else
if
p
.
PackageName
!=
f
.
Package
{
error
(
token
.
NoPos
,
"inconsistent package names: %s, %s"
,
p
.
PackageName
,
f
.
Package
)
error
_
(
token
.
NoPos
,
"inconsistent package names: %s, %s"
,
p
.
PackageName
,
f
.
Package
)
}
}
if
p
.
Name
==
nil
{
if
p
.
Name
==
nil
{
...
@@ -265,7 +265,7 @@ func (p *Package) Record(f *File) {
...
@@ -265,7 +265,7 @@ func (p *Package) Record(f *File) {
if
p
.
Name
[
k
]
==
nil
{
if
p
.
Name
[
k
]
==
nil
{
p
.
Name
[
k
]
=
v
p
.
Name
[
k
]
=
v
}
else
if
!
reflect
.
DeepEqual
(
p
.
Name
[
k
],
v
)
{
}
else
if
!
reflect
.
DeepEqual
(
p
.
Name
[
k
],
v
)
{
error
(
token
.
NoPos
,
"inconsistent definitions for C.%s"
,
k
)
error
_
(
token
.
NoPos
,
"inconsistent definitions for C.%s"
,
k
)
}
}
}
}
}
}
...
...
src/cmd/cgo/out.go
View file @
44526cdb
...
@@ -650,7 +650,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
...
@@ -650,7 +650,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
}
}
return
r
return
r
}
}
error
(
e
.
Pos
(),
"unrecognized Go type %s"
,
t
.
Name
)
error
_
(
e
.
Pos
(),
"unrecognized Go type %s"
,
t
.
Name
)
return
&
Type
{
Size
:
4
,
Align
:
4
,
C
:
c
(
"int"
)}
return
&
Type
{
Size
:
4
,
Align
:
4
,
C
:
c
(
"int"
)}
case
*
ast
.
SelectorExpr
:
case
*
ast
.
SelectorExpr
:
id
,
ok
:=
t
.
X
.
(
*
ast
.
Ident
)
id
,
ok
:=
t
.
X
.
(
*
ast
.
Ident
)
...
@@ -658,7 +658,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
...
@@ -658,7 +658,7 @@ func (p *Package) cgoType(e ast.Expr) *Type {
return
&
Type
{
Size
:
p
.
PtrSize
,
Align
:
p
.
PtrSize
,
C
:
c
(
"void*"
)}
return
&
Type
{
Size
:
p
.
PtrSize
,
Align
:
p
.
PtrSize
,
C
:
c
(
"void*"
)}
}
}
}
}
error
(
e
.
Pos
(),
"unrecognized Go type %T"
,
e
)
error
_
(
e
.
Pos
(),
"unrecognized Go type %T"
,
e
)
return
&
Type
{
Size
:
4
,
Align
:
4
,
C
:
c
(
"int"
)}
return
&
Type
{
Size
:
4
,
Align
:
4
,
C
:
c
(
"int"
)}
}
}
...
...
src/cmd/cgo/util.go
View file @
44526cdb
...
@@ -72,7 +72,7 @@ func fatalf(msg string, args ...interface{}) {
...
@@ -72,7 +72,7 @@ func fatalf(msg string, args ...interface{}) {
var
nerrors
int
var
nerrors
int
func
error
(
pos
token
.
Pos
,
msg
string
,
args
...
interface
{})
{
func
error
_
(
pos
token
.
Pos
,
msg
string
,
args
...
interface
{})
{
nerrors
++
nerrors
++
if
pos
.
IsValid
()
{
if
pos
.
IsValid
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%s: "
,
fset
.
Position
(
pos
)
.
String
())
fmt
.
Fprintf
(
os
.
Stderr
,
"%s: "
,
fset
.
Position
(
pos
)
.
String
())
...
...
src/cmd/godoc/appinit.go
View file @
44526cdb
...
@@ -11,11 +11,10 @@ import (
...
@@ -11,11 +11,10 @@ import (
"archive/zip"
"archive/zip"
"http"
"http"
"log"
"log"
"os"
"path"
"path"
)
)
func
serveError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
relpath
string
,
err
os
.
E
rror
)
{
func
serveError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
relpath
string
,
err
e
rror
)
{
contents
:=
applyTemplate
(
errorHTML
,
"errorHTML"
,
err
)
// err may contain an absolute path!
contents
:=
applyTemplate
(
errorHTML
,
"errorHTML"
,
err
)
// err may contain an absolute path!
w
.
WriteHeader
(
http
.
StatusNotFound
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
servePage
(
w
,
"File "
+
relpath
,
""
,
""
,
contents
)
servePage
(
w
,
"File "
+
relpath
,
""
,
""
,
contents
)
...
...
src/cmd/godoc/codewalk.go
View file @
44526cdb
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
package
main
package
main
import
(
import
(
"errors"
"fmt"
"fmt"
"http"
"http"
"io"
"io"
...
@@ -84,7 +85,7 @@ type Codestep struct {
...
@@ -84,7 +85,7 @@ type Codestep struct {
XML
string
`xml:"innerxml"`
XML
string
`xml:"innerxml"`
// Derived from Src; not in XML.
// Derived from Src; not in XML.
Err
os
.
E
rror
Err
e
rror
File
string
File
string
Lo
int
Lo
int
LoByte
int
LoByte
int
...
@@ -107,7 +108,7 @@ func (st *Codestep) String() string {
...
@@ -107,7 +108,7 @@ func (st *Codestep) String() string {
}
}
// loadCodewalk reads a codewalk from the named XML file.
// loadCodewalk reads a codewalk from the named XML file.
func
loadCodewalk
(
filename
string
)
(
*
Codewalk
,
os
.
E
rror
)
{
func
loadCodewalk
(
filename
string
)
(
*
Codewalk
,
e
rror
)
{
f
,
err
:=
fs
.
Open
(
filename
)
f
,
err
:=
fs
.
Open
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -252,7 +253,7 @@ func codewalkFileprint(w http.ResponseWriter, r *http.Request, f string) {
...
@@ -252,7 +253,7 @@ func codewalkFileprint(w http.ResponseWriter, r *http.Request, f string) {
// It returns the lo and hi byte offset of the matched region within data.
// It returns the lo and hi byte offset of the matched region within data.
// See http://plan9.bell-labs.com/sys/doc/sam/sam.html Table II
// See http://plan9.bell-labs.com/sys/doc/sam/sam.html Table II
// for details on the syntax.
// for details on the syntax.
func
addrToByteRange
(
addr
string
,
start
int
,
data
[]
byte
)
(
lo
,
hi
int
,
err
os
.
E
rror
)
{
func
addrToByteRange
(
addr
string
,
start
int
,
data
[]
byte
)
(
lo
,
hi
int
,
err
e
rror
)
{
var
(
var
(
dir
byte
dir
byte
prevc
byte
prevc
byte
...
@@ -264,7 +265,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er
...
@@ -264,7 +265,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er
c
:=
addr
[
0
]
c
:=
addr
[
0
]
switch
c
{
switch
c
{
default
:
default
:
err
=
os
.
NewError
(
"invalid address syntax near "
+
string
(
c
))
err
=
errors
.
New
(
"invalid address syntax near "
+
string
(
c
))
case
','
:
case
','
:
if
len
(
addr
)
==
1
{
if
len
(
addr
)
==
1
{
hi
=
len
(
data
)
hi
=
len
(
data
)
...
@@ -348,7 +349,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er
...
@@ -348,7 +349,7 @@ func addrToByteRange(addr string, start int, data []byte) (lo, hi int, err os.Er
// (or characters) after hi. Applying -n (or -#n) means to back up n lines
// (or characters) after hi. Applying -n (or -#n) means to back up n lines
// (or characters) before lo.
// (or characters) before lo.
// The return value is the new lo, hi.
// The return value is the new lo, hi.
func
addrNumber
(
data
[]
byte
,
lo
,
hi
int
,
dir
byte
,
n
int
,
charOffset
bool
)
(
int
,
int
,
os
.
E
rror
)
{
func
addrNumber
(
data
[]
byte
,
lo
,
hi
int
,
dir
byte
,
n
int
,
charOffset
bool
)
(
int
,
int
,
e
rror
)
{
switch
dir
{
switch
dir
{
case
0
:
case
0
:
lo
=
0
lo
=
0
...
@@ -424,13 +425,13 @@ func addrNumber(data []byte, lo, hi int, dir byte, n int, charOffset bool) (int,
...
@@ -424,13 +425,13 @@ func addrNumber(data []byte, lo, hi int, dir byte, n int, charOffset bool) (int,
}
}
}
}
return
0
,
0
,
os
.
NewError
(
"address out of range"
)
return
0
,
0
,
errors
.
New
(
"address out of range"
)
}
}
// addrRegexp searches for pattern in the given direction starting at lo, hi.
// addrRegexp searches for pattern in the given direction starting at lo, hi.
// The direction dir is '+' (search forward from hi) or '-' (search backward from lo).
// The direction dir is '+' (search forward from hi) or '-' (search backward from lo).
// Backward searches are unimplemented.
// Backward searches are unimplemented.
func
addrRegexp
(
data
[]
byte
,
lo
,
hi
int
,
dir
byte
,
pattern
string
)
(
int
,
int
,
os
.
E
rror
)
{
func
addrRegexp
(
data
[]
byte
,
lo
,
hi
int
,
dir
byte
,
pattern
string
)
(
int
,
int
,
e
rror
)
{
re
,
err
:=
regexp
.
Compile
(
pattern
)
re
,
err
:=
regexp
.
Compile
(
pattern
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
0
,
err
return
0
,
0
,
err
...
@@ -438,7 +439,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os
...
@@ -438,7 +439,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os
if
dir
==
'-'
{
if
dir
==
'-'
{
// Could implement reverse search using binary search
// Could implement reverse search using binary search
// through file, but that seems like overkill.
// through file, but that seems like overkill.
return
0
,
0
,
os
.
NewError
(
"reverse search not implemented"
)
return
0
,
0
,
errors
.
New
(
"reverse search not implemented"
)
}
}
m
:=
re
.
FindIndex
(
data
[
hi
:
])
m
:=
re
.
FindIndex
(
data
[
hi
:
])
if
len
(
m
)
>
0
{
if
len
(
m
)
>
0
{
...
@@ -449,7 +450,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os
...
@@ -449,7 +450,7 @@ func addrRegexp(data []byte, lo, hi int, dir byte, pattern string) (int, int, os
m
=
re
.
FindIndex
(
data
)
m
=
re
.
FindIndex
(
data
)
}
}
if
len
(
m
)
==
0
{
if
len
(
m
)
==
0
{
return
0
,
0
,
os
.
NewError
(
"no match for "
+
pattern
)
return
0
,
0
,
errors
.
New
(
"no match for "
+
pattern
)
}
}
return
m
[
0
],
m
[
1
],
nil
return
m
[
0
],
m
[
1
],
nil
}
}
...
...
src/cmd/godoc/filesystem.go
View file @
44526cdb
...
@@ -27,14 +27,14 @@ type FileInfo interface {
...
@@ -27,14 +27,14 @@ type FileInfo interface {
// The FileSystem interface specifies the methods godoc is using
// The FileSystem interface specifies the methods godoc is using
// to access the file system for which it serves documentation.
// to access the file system for which it serves documentation.
type
FileSystem
interface
{
type
FileSystem
interface
{
Open
(
path
string
)
(
io
.
ReadCloser
,
os
.
E
rror
)
Open
(
path
string
)
(
io
.
ReadCloser
,
e
rror
)
Lstat
(
path
string
)
(
FileInfo
,
os
.
E
rror
)
Lstat
(
path
string
)
(
FileInfo
,
e
rror
)
Stat
(
path
string
)
(
FileInfo
,
os
.
E
rror
)
Stat
(
path
string
)
(
FileInfo
,
e
rror
)
ReadDir
(
path
string
)
([]
FileInfo
,
os
.
E
rror
)
ReadDir
(
path
string
)
([]
FileInfo
,
e
rror
)
}
}
// ReadFile reads the file named by path from fs and returns the contents.
// ReadFile reads the file named by path from fs and returns the contents.
func
ReadFile
(
fs
FileSystem
,
path
string
)
([]
byte
,
os
.
E
rror
)
{
func
ReadFile
(
fs
FileSystem
,
path
string
)
([]
byte
,
e
rror
)
{
rc
,
err
:=
fs
.
Open
(
path
)
rc
,
err
:=
fs
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -71,7 +71,7 @@ func (fi osFI) Mtime_ns() int64 {
...
@@ -71,7 +71,7 @@ func (fi osFI) Mtime_ns() int64 {
// osFS is the OS-specific implementation of FileSystem
// osFS is the OS-specific implementation of FileSystem
type
osFS
struct
{}
type
osFS
struct
{}
func
(
osFS
)
Open
(
path
string
)
(
io
.
ReadCloser
,
os
.
E
rror
)
{
func
(
osFS
)
Open
(
path
string
)
(
io
.
ReadCloser
,
e
rror
)
{
f
,
err
:=
os
.
Open
(
path
)
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -86,17 +86,17 @@ func (osFS) Open(path string) (io.ReadCloser, os.Error) {
...
@@ -86,17 +86,17 @@ func (osFS) Open(path string) (io.ReadCloser, os.Error) {
return
f
,
nil
return
f
,
nil
}
}
func
(
osFS
)
Lstat
(
path
string
)
(
FileInfo
,
os
.
E
rror
)
{
func
(
osFS
)
Lstat
(
path
string
)
(
FileInfo
,
e
rror
)
{
fi
,
err
:=
os
.
Lstat
(
path
)
fi
,
err
:=
os
.
Lstat
(
path
)
return
osFI
{
fi
},
err
return
osFI
{
fi
},
err
}
}
func
(
osFS
)
Stat
(
path
string
)
(
FileInfo
,
os
.
E
rror
)
{
func
(
osFS
)
Stat
(
path
string
)
(
FileInfo
,
e
rror
)
{
fi
,
err
:=
os
.
Stat
(
path
)
fi
,
err
:=
os
.
Stat
(
path
)
return
osFI
{
fi
},
err
return
osFI
{
fi
},
err
}
}
func
(
osFS
)
ReadDir
(
path
string
)
([]
FileInfo
,
os
.
E
rror
)
{
func
(
osFS
)
ReadDir
(
path
string
)
([]
FileInfo
,
e
rror
)
{
l0
,
err
:=
ioutil
.
ReadDir
(
path
)
// l0 is sorted
l0
,
err
:=
ioutil
.
ReadDir
(
path
)
// l0 is sorted
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
src/cmd/godoc/godoc.go
View file @
44526cdb
...
@@ -148,7 +148,7 @@ func getPathFilter() func(string) bool {
...
@@ -148,7 +148,7 @@ func getPathFilter() func(string) bool {
// readDirList reads a file containing a newline-separated list
// readDirList reads a file containing a newline-separated list
// of directory paths and returns the list of paths.
// of directory paths and returns the list of paths.
func
readDirList
(
filename
string
)
([]
string
,
os
.
E
rror
)
{
func
readDirList
(
filename
string
)
([]
string
,
e
rror
)
{
contents
,
err
:=
ReadFile
(
fs
,
filename
)
contents
,
err
:=
ReadFile
(
fs
,
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -299,7 +299,7 @@ type tconv struct {
...
@@ -299,7 +299,7 @@ type tconv struct {
indent
int
// valid if state == indenting
indent
int
// valid if state == indenting
}
}
func
(
p
*
tconv
)
writeIndent
()
(
err
os
.
E
rror
)
{
func
(
p
*
tconv
)
writeIndent
()
(
err
e
rror
)
{
i
:=
p
.
indent
i
:=
p
.
indent
for
i
>=
len
(
spaces
)
{
for
i
>=
len
(
spaces
)
{
i
-=
len
(
spaces
)
i
-=
len
(
spaces
)
...
@@ -314,7 +314,7 @@ func (p *tconv) writeIndent() (err os.Error) {
...
@@ -314,7 +314,7 @@ func (p *tconv) writeIndent() (err os.Error) {
return
return
}
}
func
(
p
*
tconv
)
Write
(
data
[]
byte
)
(
n
int
,
err
os
.
E
rror
)
{
func
(
p
*
tconv
)
Write
(
data
[]
byte
)
(
n
int
,
err
e
rror
)
{
if
len
(
data
)
==
0
{
if
len
(
data
)
==
0
{
return
return
}
}
...
@@ -855,7 +855,7 @@ type PageInfo struct {
...
@@ -855,7 +855,7 @@ type PageInfo struct {
Dirs
*
DirList
// nil if no directory information
Dirs
*
DirList
// nil if no directory information
DirTime
int64
// directory time stamp in seconds since epoch
DirTime
int64
// directory time stamp in seconds since epoch
IsPkg
bool
// false if this is not documenting a real package
IsPkg
bool
// false if this is not documenting a real package
Err
os
.
Error
// directory read error or nil
Err
error
// directory read error or nil
}
}
func
(
info
*
PageInfo
)
IsEmpty
()
bool
{
func
(
info
*
PageInfo
)
IsEmpty
()
bool
{
...
@@ -869,7 +869,7 @@ type httpHandler struct {
...
@@ -869,7 +869,7 @@ type httpHandler struct {
}
}
// fsReadDir implements ReadDir for the go/build package.
// fsReadDir implements ReadDir for the go/build package.
func
fsReadDir
(
dir
string
)
([]
*
os
.
FileInfo
,
os
.
E
rror
)
{
func
fsReadDir
(
dir
string
)
([]
*
os
.
FileInfo
,
e
rror
)
{
fi
,
err
:=
fs
.
ReadDir
(
dir
)
fi
,
err
:=
fs
.
ReadDir
(
dir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -888,7 +888,7 @@ func fsReadDir(dir string) ([]*os.FileInfo, os.Error) {
...
@@ -888,7 +888,7 @@ func fsReadDir(dir string) ([]*os.FileInfo, os.Error) {
}
}
// fsReadFile implements ReadFile for the go/build package.
// fsReadFile implements ReadFile for the go/build package.
func
fsReadFile
(
dir
,
name
string
)
(
path
string
,
data
[]
byte
,
err
os
.
E
rror
)
{
func
fsReadFile
(
dir
,
name
string
)
(
path
string
,
data
[]
byte
,
err
e
rror
)
{
path
=
filepath
.
Join
(
dir
,
name
)
path
=
filepath
.
Join
(
dir
,
name
)
data
,
err
=
ReadFile
(
fs
,
path
)
data
,
err
=
ReadFile
(
fs
,
path
)
return
return
...
@@ -1172,12 +1172,12 @@ func lookup(query string) (result SearchResult) {
...
@@ -1172,12 +1172,12 @@ func lookup(query string) (result SearchResult) {
index
:=
index
.
(
*
Index
)
index
:=
index
.
(
*
Index
)
// identifier search
// identifier search
var
err
os
.
E
rror
var
err
e
rror
result
.
Pak
,
result
.
Hit
,
result
.
Alt
,
err
=
index
.
Lookup
(
query
)
result
.
Pak
,
result
.
Hit
,
result
.
Alt
,
err
=
index
.
Lookup
(
query
)
if
err
!=
nil
&&
*
maxResults
<=
0
{
if
err
!=
nil
&&
*
maxResults
<=
0
{
// ignore the error if full text search is enabled
// ignore the error if full text search is enabled
// since the query may be a valid regular expression
// since the query may be a valid regular expression
result
.
Alert
=
"Error in query string: "
+
err
.
String
()
result
.
Alert
=
"Error in query string: "
+
err
.
Error
()
return
return
}
}
...
@@ -1185,7 +1185,7 @@ func lookup(query string) (result SearchResult) {
...
@@ -1185,7 +1185,7 @@ func lookup(query string) (result SearchResult) {
if
*
maxResults
>
0
&&
query
!=
""
{
if
*
maxResults
>
0
&&
query
!=
""
{
rx
,
err
:=
regexp
.
Compile
(
query
)
rx
,
err
:=
regexp
.
Compile
(
query
)
if
err
!=
nil
{
if
err
!=
nil
{
result
.
Alert
=
"Error in query regular expression: "
+
err
.
String
()
result
.
Alert
=
"Error in query regular expression: "
+
err
.
Error
()
return
return
}
}
// If we get maxResults+1 results we know that there are more than
// If we get maxResults+1 results we know that there are more than
...
@@ -1280,7 +1280,7 @@ func fsDirnames() <-chan string {
...
@@ -1280,7 +1280,7 @@ func fsDirnames() <-chan string {
return
c
return
c
}
}
func
readIndex
(
filenames
string
)
os
.
E
rror
{
func
readIndex
(
filenames
string
)
e
rror
{
matches
,
err
:=
filepath
.
Glob
(
filenames
)
matches
,
err
:=
filepath
.
Glob
(
filenames
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
src/cmd/godoc/httpzip.go
View file @
44526cdb
...
@@ -50,7 +50,7 @@ type httpZipFile struct {
...
@@ -50,7 +50,7 @@ type httpZipFile struct {
list
zipList
list
zipList
}
}
func
(
f
*
httpZipFile
)
Close
()
os
.
E
rror
{
func
(
f
*
httpZipFile
)
Close
()
e
rror
{
if
f
.
info
.
IsRegular
()
{
if
f
.
info
.
IsRegular
()
{
return
f
.
ReadCloser
.
Close
()
return
f
.
ReadCloser
.
Close
()
}
}
...
@@ -58,11 +58,11 @@ func (f *httpZipFile) Close() os.Error {
...
@@ -58,11 +58,11 @@ func (f *httpZipFile) Close() os.Error {
return
nil
return
nil
}
}
func
(
f
*
httpZipFile
)
Stat
()
(
*
os
.
FileInfo
,
os
.
E
rror
)
{
func
(
f
*
httpZipFile
)
Stat
()
(
*
os
.
FileInfo
,
e
rror
)
{
return
&
f
.
info
,
nil
return
&
f
.
info
,
nil
}
}
func
(
f
*
httpZipFile
)
Readdir
(
count
int
)
([]
os
.
FileInfo
,
os
.
E
rror
)
{
func
(
f
*
httpZipFile
)
Readdir
(
count
int
)
([]
os
.
FileInfo
,
e
rror
)
{
var
list
[]
os
.
FileInfo
var
list
[]
os
.
FileInfo
dirname
:=
f
.
path
+
"/"
dirname
:=
f
.
path
+
"/"
prevname
:=
""
prevname
:=
""
...
@@ -106,13 +106,13 @@ func (f *httpZipFile) Readdir(count int) ([]os.FileInfo, os.Error) {
...
@@ -106,13 +106,13 @@ func (f *httpZipFile) Readdir(count int) ([]os.FileInfo, os.Error) {
}
}
if
count
>=
0
&&
len
(
list
)
==
0
{
if
count
>=
0
&&
len
(
list
)
==
0
{
return
nil
,
os
.
EOF
return
nil
,
io
.
EOF
}
}
return
list
,
nil
return
list
,
nil
}
}
func
(
f
*
httpZipFile
)
Seek
(
offset
int64
,
whence
int
)
(
int64
,
os
.
E
rror
)
{
func
(
f
*
httpZipFile
)
Seek
(
offset
int64
,
whence
int
)
(
int64
,
e
rror
)
{
return
0
,
fmt
.
Errorf
(
"Seek not implemented for zip file entry: %s"
,
f
.
info
.
Name
)
return
0
,
fmt
.
Errorf
(
"Seek not implemented for zip file entry: %s"
,
f
.
info
.
Name
)
}
}
...
@@ -123,7 +123,7 @@ type httpZipFS struct {
...
@@ -123,7 +123,7 @@ type httpZipFS struct {
root
string
root
string
}
}
func
(
fs
*
httpZipFS
)
Open
(
name
string
)
(
http
.
File
,
os
.
E
rror
)
{
func
(
fs
*
httpZipFS
)
Open
(
name
string
)
(
http
.
File
,
e
rror
)
{
// fs.root does not start with '/'.
// fs.root does not start with '/'.
path
:=
path
.
Join
(
fs
.
root
,
name
)
// path is clean
path
:=
path
.
Join
(
fs
.
root
,
name
)
// path is clean
index
,
exact
:=
fs
.
list
.
lookup
(
path
)
index
,
exact
:=
fs
.
list
.
lookup
(
path
)
...
@@ -165,7 +165,7 @@ func (fs *httpZipFS) Open(name string) (http.File, os.Error) {
...
@@ -165,7 +165,7 @@ func (fs *httpZipFS) Open(name string) (http.File, os.Error) {
},
nil
},
nil
}
}
func
(
fs
*
httpZipFS
)
Close
()
os
.
E
rror
{
func
(
fs
*
httpZipFS
)
Close
()
e
rror
{
fs
.
list
=
nil
fs
.
list
=
nil
return
fs
.
ReadCloser
.
Close
()
return
fs
.
ReadCloser
.
Close
()
}
}
...
...
src/cmd/godoc/index.go
View file @
44526cdb
...
@@ -40,6 +40,7 @@ package main
...
@@ -40,6 +40,7 @@ package main
import
(
import
(
"bufio"
"bufio"
"bytes"
"bytes"
"errors"
"go/ast"
"go/ast"
"go/parser"
"go/parser"
"go/token"
"go/token"
...
@@ -47,7 +48,6 @@ import (
...
@@ -47,7 +48,6 @@ import (
"gob"
"gob"
"index/suffixarray"
"index/suffixarray"
"io"
"io"
"os"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"sort"
"sort"
...
@@ -841,16 +841,16 @@ type fileIndex struct {
...
@@ -841,16 +841,16 @@ type fileIndex struct {
Fulltext
bool
Fulltext
bool
}
}
func
(
x
*
fileIndex
)
Write
(
w
io
.
Writer
)
os
.
E
rror
{
func
(
x
*
fileIndex
)
Write
(
w
io
.
Writer
)
e
rror
{
return
gob
.
NewEncoder
(
w
)
.
Encode
(
x
)
return
gob
.
NewEncoder
(
w
)
.
Encode
(
x
)
}
}
func
(
x
*
fileIndex
)
Read
(
r
io
.
Reader
)
os
.
E
rror
{
func
(
x
*
fileIndex
)
Read
(
r
io
.
Reader
)
e
rror
{
return
gob
.
NewDecoder
(
r
)
.
Decode
(
x
)
return
gob
.
NewDecoder
(
r
)
.
Decode
(
x
)
}
}
// Write writes the index x to w.
// Write writes the index x to w.
func
(
x
*
Index
)
Write
(
w
io
.
Writer
)
os
.
E
rror
{
func
(
x
*
Index
)
Write
(
w
io
.
Writer
)
e
rror
{
fulltext
:=
false
fulltext
:=
false
if
x
.
suffixes
!=
nil
{
if
x
.
suffixes
!=
nil
{
fulltext
=
true
fulltext
=
true
...
@@ -877,7 +877,7 @@ func (x *Index) Write(w io.Writer) os.Error {
...
@@ -877,7 +877,7 @@ func (x *Index) Write(w io.Writer) os.Error {
// Read reads the index from r into x; x must not be nil.
// Read reads the index from r into x; x must not be nil.
// If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.
// If r does not also implement io.ByteReader, it will be wrapped in a bufio.Reader.
func
(
x
*
Index
)
Read
(
r
io
.
Reader
)
os
.
E
rror
{
func
(
x
*
Index
)
Read
(
r
io
.
Reader
)
e
rror
{
// We use the ability to read bytes as a plausible surrogate for buffering.
// We use the ability to read bytes as a plausible surrogate for buffering.
if
_
,
ok
:=
r
.
(
io
.
ByteReader
);
!
ok
{
if
_
,
ok
:=
r
.
(
io
.
ByteReader
);
!
ok
{
r
=
bufio
.
NewReader
(
r
)
r
=
bufio
.
NewReader
(
r
)
...
@@ -934,13 +934,13 @@ func isIdentifier(s string) bool {
...
@@ -934,13 +934,13 @@ func isIdentifier(s string) bool {
// identifier, Lookup returns a list of packages, a LookupResult, and a
// identifier, Lookup returns a list of packages, a LookupResult, and a
// list of alternative spellings, if any. Any and all results may be nil.
// list of alternative spellings, if any. Any and all results may be nil.
// If the query syntax is wrong, an error is reported.
// If the query syntax is wrong, an error is reported.
func
(
x
*
Index
)
Lookup
(
query
string
)
(
paks
HitList
,
match
*
LookupResult
,
alt
*
AltWords
,
err
os
.
E
rror
)
{
func
(
x
*
Index
)
Lookup
(
query
string
)
(
paks
HitList
,
match
*
LookupResult
,
alt
*
AltWords
,
err
e
rror
)
{
ss
:=
strings
.
Split
(
query
,
"."
)
ss
:=
strings
.
Split
(
query
,
"."
)
// check query syntax
// check query syntax
for
_
,
s
:=
range
ss
{
for
_
,
s
:=
range
ss
{
if
!
isIdentifier
(
s
)
{
if
!
isIdentifier
(
s
)
{
err
=
os
.
NewError
(
"all query parts must be identifiers"
)
err
=
errors
.
New
(
"all query parts must be identifiers"
)
return
return
}
}
}
}
...
@@ -968,7 +968,7 @@ func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *Al
...
@@ -968,7 +968,7 @@ func (x *Index) Lookup(query string) (paks HitList, match *LookupResult, alt *Al
}
}
default
:
default
:
err
=
os
.
NewError
(
"query is not a (qualified) identifier"
)
err
=
errors
.
New
(
"query is not a (qualified) identifier"
)
}
}
return
return
...
...
src/cmd/godoc/main.go
View file @
44526cdb
...
@@ -28,6 +28,7 @@ package main
...
@@ -28,6 +28,7 @@ package main
import
(
import
(
"archive/zip"
"archive/zip"
"bytes"
"bytes"
"errors"
_
"expvar"
// to serve /debug/vars
_
"expvar"
// to serve /debug/vars
"flag"
"flag"
"fmt"
"fmt"
...
@@ -74,7 +75,7 @@ var (
...
@@ -74,7 +75,7 @@ var (
query
=
flag
.
Bool
(
"q"
,
false
,
"arguments are considered search queries"
)
query
=
flag
.
Bool
(
"q"
,
false
,
"arguments are considered search queries"
)
)
)
func
serveError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
relpath
string
,
err
os
.
E
rror
)
{
func
serveError
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
relpath
string
,
err
e
rror
)
{
contents
:=
applyTemplate
(
errorHTML
,
"errorHTML"
,
err
)
// err may contain an absolute path!
contents
:=
applyTemplate
(
errorHTML
,
"errorHTML"
,
err
)
// err may contain an absolute path!
w
.
WriteHeader
(
http
.
StatusNotFound
)
w
.
WriteHeader
(
http
.
StatusNotFound
)
servePage
(
w
,
"File "
+
relpath
,
""
,
""
,
contents
)
servePage
(
w
,
"File "
+
relpath
,
""
,
""
,
contents
)
...
@@ -163,7 +164,7 @@ func loggingHandler(h http.Handler) http.Handler {
...
@@ -163,7 +164,7 @@ func loggingHandler(h http.Handler) http.Handler {
})
})
}
}
func
remoteSearch
(
query
string
)
(
res
*
http
.
Response
,
err
os
.
E
rror
)
{
func
remoteSearch
(
query
string
)
(
res
*
http
.
Response
,
err
e
rror
)
{
search
:=
"/search?f=text&q="
+
url
.
QueryEscape
(
query
)
search
:=
"/search?f=text&q="
+
url
.
QueryEscape
(
query
)
// list of addresses to try
// list of addresses to try
...
@@ -188,7 +189,7 @@ func remoteSearch(query string) (res *http.Response, err os.Error) {
...
@@ -188,7 +189,7 @@ func remoteSearch(query string) (res *http.Response, err os.Error) {
}
}
if
err
==
nil
&&
res
.
StatusCode
!=
http
.
StatusOK
{
if
err
==
nil
&&
res
.
StatusCode
!=
http
.
StatusOK
{
err
=
os
.
NewError
(
res
.
Status
)
err
=
errors
.
New
(
res
.
Status
)
}
}
return
return
...
...
src/cmd/godoc/parser.go
View file @
44526cdb
...
@@ -13,11 +13,10 @@ import (
...
@@ -13,11 +13,10 @@ import (
"go/ast"
"go/ast"
"go/parser"
"go/parser"
"go/token"
"go/token"
"os"
"path/filepath"
"path/filepath"
)
)
func
parseFile
(
fset
*
token
.
FileSet
,
filename
string
,
mode
uint
)
(
*
ast
.
File
,
os
.
E
rror
)
{
func
parseFile
(
fset
*
token
.
FileSet
,
filename
string
,
mode
uint
)
(
*
ast
.
File
,
e
rror
)
{
src
,
err
:=
ReadFile
(
fs
,
filename
)
src
,
err
:=
ReadFile
(
fs
,
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -25,7 +24,7 @@ func parseFile(fset *token.FileSet, filename string, mode uint) (*ast.File, os.E
...
@@ -25,7 +24,7 @@ func parseFile(fset *token.FileSet, filename string, mode uint) (*ast.File, os.E
return
parser
.
ParseFile
(
fset
,
filename
,
src
,
mode
)
return
parser
.
ParseFile
(
fset
,
filename
,
src
,
mode
)
}
}
func
parseFiles
(
fset
*
token
.
FileSet
,
filenames
[]
string
)
(
pkgs
map
[
string
]
*
ast
.
Package
,
first
os
.
E
rror
)
{
func
parseFiles
(
fset
*
token
.
FileSet
,
filenames
[]
string
)
(
pkgs
map
[
string
]
*
ast
.
Package
,
first
e
rror
)
{
pkgs
=
make
(
map
[
string
]
*
ast
.
Package
)
pkgs
=
make
(
map
[
string
]
*
ast
.
Package
)
for
_
,
filename
:=
range
filenames
{
for
_
,
filename
:=
range
filenames
{
file
,
err
:=
parseFile
(
fset
,
filename
,
parser
.
ParseComments
)
file
,
err
:=
parseFile
(
fset
,
filename
,
parser
.
ParseComments
)
...
@@ -48,7 +47,7 @@ func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.P
...
@@ -48,7 +47,7 @@ func parseFiles(fset *token.FileSet, filenames []string) (pkgs map[string]*ast.P
return
return
}
}
func
parseDir
(
fset
*
token
.
FileSet
,
path
string
,
filter
func
(
FileInfo
)
bool
)
(
map
[
string
]
*
ast
.
Package
,
os
.
E
rror
)
{
func
parseDir
(
fset
*
token
.
FileSet
,
path
string
,
filter
func
(
FileInfo
)
bool
)
(
map
[
string
]
*
ast
.
Package
,
e
rror
)
{
list
,
err
:=
fs
.
ReadDir
(
path
)
list
,
err
:=
fs
.
ReadDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
src/cmd/godoc/utils.go
View file @
44526cdb
...
@@ -93,7 +93,7 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string {
...
@@ -93,7 +93,7 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string {
// writeFileAtomically writes data to a temporary file and then
// writeFileAtomically writes data to a temporary file and then
// atomically renames that file to the file named by filename.
// atomically renames that file to the file named by filename.
//
//
func
writeFileAtomically
(
filename
string
,
data
[]
byte
)
os
.
E
rror
{
func
writeFileAtomically
(
filename
string
,
data
[]
byte
)
e
rror
{
// TODO(gri) this won't work on appengine
// TODO(gri) this won't work on appengine
f
,
err
:=
ioutil
.
TempFile
(
filepath
.
Split
(
filename
))
f
,
err
:=
ioutil
.
TempFile
(
filepath
.
Split
(
filename
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
src/cmd/godoc/zip.go
View file @
44526cdb
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"archive/zip"
"archive/zip"
"fmt"
"fmt"
"io"
"io"
"os"
"path"
"path"
"sort"
"sort"
"strings"
"strings"
...
@@ -66,7 +65,7 @@ type zipFS struct {
...
@@ -66,7 +65,7 @@ type zipFS struct {
list
zipList
list
zipList
}
}
func
(
fs
*
zipFS
)
Close
()
os
.
E
rror
{
func
(
fs
*
zipFS
)
Close
()
e
rror
{
fs
.
list
=
nil
fs
.
list
=
nil
return
fs
.
ReadCloser
.
Close
()
return
fs
.
ReadCloser
.
Close
()
}
}
...
@@ -79,7 +78,7 @@ func zipPath(name string) string {
...
@@ -79,7 +78,7 @@ func zipPath(name string) string {
return
name
[
1
:
]
// strip leading '/'
return
name
[
1
:
]
// strip leading '/'
}
}
func
(
fs
*
zipFS
)
stat
(
abspath
string
)
(
int
,
zipFI
,
os
.
E
rror
)
{
func
(
fs
*
zipFS
)
stat
(
abspath
string
)
(
int
,
zipFI
,
e
rror
)
{
i
,
exact
:=
fs
.
list
.
lookup
(
abspath
)
i
,
exact
:=
fs
.
list
.
lookup
(
abspath
)
if
i
<
0
{
if
i
<
0
{
// abspath has leading '/' stripped - print it explicitly
// abspath has leading '/' stripped - print it explicitly
...
@@ -93,7 +92,7 @@ func (fs *zipFS) stat(abspath string) (int, zipFI, os.Error) {
...
@@ -93,7 +92,7 @@ func (fs *zipFS) stat(abspath string) (int, zipFI, os.Error) {
return
i
,
zipFI
{
name
,
file
},
nil
return
i
,
zipFI
{
name
,
file
},
nil
}
}
func
(
fs
*
zipFS
)
Open
(
abspath
string
)
(
io
.
ReadCloser
,
os
.
E
rror
)
{
func
(
fs
*
zipFS
)
Open
(
abspath
string
)
(
io
.
ReadCloser
,
e
rror
)
{
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -104,17 +103,17 @@ func (fs *zipFS) Open(abspath string) (io.ReadCloser, os.Error) {
...
@@ -104,17 +103,17 @@ func (fs *zipFS) Open(abspath string) (io.ReadCloser, os.Error) {
return
fi
.
file
.
Open
()
return
fi
.
file
.
Open
()
}
}
func
(
fs
*
zipFS
)
Lstat
(
abspath
string
)
(
FileInfo
,
os
.
E
rror
)
{
func
(
fs
*
zipFS
)
Lstat
(
abspath
string
)
(
FileInfo
,
e
rror
)
{
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
return
fi
,
err
return
fi
,
err
}
}
func
(
fs
*
zipFS
)
Stat
(
abspath
string
)
(
FileInfo
,
os
.
E
rror
)
{
func
(
fs
*
zipFS
)
Stat
(
abspath
string
)
(
FileInfo
,
e
rror
)
{
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
_
,
fi
,
err
:=
fs
.
stat
(
zipPath
(
abspath
))
return
fi
,
err
return
fi
,
err
}
}
func
(
fs
*
zipFS
)
ReadDir
(
abspath
string
)
([]
FileInfo
,
os
.
E
rror
)
{
func
(
fs
*
zipFS
)
ReadDir
(
abspath
string
)
([]
FileInfo
,
e
rror
)
{
path
:=
zipPath
(
abspath
)
path
:=
zipPath
(
abspath
)
i
,
fi
,
err
:=
fs
.
stat
(
path
)
i
,
fi
,
err
:=
fs
.
stat
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
src/cmd/gofix/main.go
View file @
44526cdb
...
@@ -102,9 +102,9 @@ var printConfig = &printer.Config{
...
@@ -102,9 +102,9 @@ var printConfig = &printer.Config{
tabWidth
,
tabWidth
,
}
}
func
processFile
(
filename
string
,
useStdin
bool
)
os
.
E
rror
{
func
processFile
(
filename
string
,
useStdin
bool
)
e
rror
{
var
f
*
os
.
File
var
f
*
os
.
File
var
err
os
.
E
rror
var
err
e
rror
var
fixlog
bytes
.
Buffer
var
fixlog
bytes
.
Buffer
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
...
@@ -196,12 +196,12 @@ func gofmt(n interface{}) string {
...
@@ -196,12 +196,12 @@ func gofmt(n interface{}) string {
gofmtBuf
.
Reset
()
gofmtBuf
.
Reset
()
_
,
err
:=
printConfig
.
Fprint
(
&
gofmtBuf
,
fset
,
n
)
_
,
err
:=
printConfig
.
Fprint
(
&
gofmtBuf
,
fset
,
n
)
if
err
!=
nil
{
if
err
!=
nil
{
return
"<"
+
err
.
String
()
+
">"
return
"<"
+
err
.
Error
()
+
">"
}
}
return
gofmtBuf
.
String
()
return
gofmtBuf
.
String
()
}
}
func
report
(
err
os
.
E
rror
)
{
func
report
(
err
e
rror
)
{
scanner
.
PrintError
(
os
.
Stderr
,
err
)
scanner
.
PrintError
(
os
.
Stderr
,
err
)
exitCode
=
2
exitCode
=
2
}
}
...
@@ -210,7 +210,7 @@ func walkDir(path string) {
...
@@ -210,7 +210,7 @@ func walkDir(path string) {
filepath
.
Walk
(
path
,
visitFile
)
filepath
.
Walk
(
path
,
visitFile
)
}
}
func
visitFile
(
path
string
,
f
*
os
.
FileInfo
,
err
os
.
Error
)
os
.
E
rror
{
func
visitFile
(
path
string
,
f
*
os
.
FileInfo
,
err
error
)
e
rror
{
if
err
==
nil
&&
isGoFile
(
f
)
{
if
err
==
nil
&&
isGoFile
(
f
)
{
err
=
processFile
(
path
,
false
)
err
=
processFile
(
path
,
false
)
}
}
...
@@ -225,7 +225,7 @@ func isGoFile(f *os.FileInfo) bool {
...
@@ -225,7 +225,7 @@ func isGoFile(f *os.FileInfo) bool {
return
f
.
IsRegular
()
&&
!
strings
.
HasPrefix
(
f
.
Name
,
"."
)
&&
strings
.
HasSuffix
(
f
.
Name
,
".go"
)
return
f
.
IsRegular
()
&&
!
strings
.
HasPrefix
(
f
.
Name
,
"."
)
&&
strings
.
HasSuffix
(
f
.
Name
,
".go"
)
}
}
func
diff
(
b1
,
b2
[]
byte
)
(
data
[]
byte
,
err
os
.
E
rror
)
{
func
diff
(
b1
,
b2
[]
byte
)
(
data
[]
byte
,
err
e
rror
)
{
f1
,
err
:=
ioutil
.
TempFile
(
""
,
"gofix"
)
f1
,
err
:=
ioutil
.
TempFile
(
""
,
"gofix"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
src/cmd/gofmt/gofmt.go
View file @
44526cdb
...
@@ -49,7 +49,7 @@ var (
...
@@ -49,7 +49,7 @@ var (
printerMode
uint
printerMode
uint
)
)
func
report
(
err
os
.
E
rror
)
{
func
report
(
err
e
rror
)
{
scanner
.
PrintError
(
os
.
Stderr
,
err
)
scanner
.
PrintError
(
os
.
Stderr
,
err
)
exitCode
=
2
exitCode
=
2
}
}
...
@@ -86,7 +86,7 @@ func isGoFile(f *os.FileInfo) bool {
...
@@ -86,7 +86,7 @@ func isGoFile(f *os.FileInfo) bool {
}
}
// If in == nil, the source is the contents of the file with the given filename.
// If in == nil, the source is the contents of the file with the given filename.
func
processFile
(
filename
string
,
in
io
.
Reader
,
out
io
.
Writer
,
stdin
bool
)
os
.
E
rror
{
func
processFile
(
filename
string
,
in
io
.
Reader
,
out
io
.
Writer
,
stdin
bool
)
e
rror
{
if
in
==
nil
{
if
in
==
nil
{
f
,
err
:=
os
.
Open
(
filename
)
f
,
err
:=
os
.
Open
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -156,7 +156,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) os.Er
...
@@ -156,7 +156,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) os.Er
return
err
return
err
}
}
func
visitFile
(
path
string
,
f
*
os
.
FileInfo
,
err
os
.
Error
)
os
.
E
rror
{
func
visitFile
(
path
string
,
f
*
os
.
FileInfo
,
err
error
)
e
rror
{
if
err
==
nil
&&
isGoFile
(
f
)
{
if
err
==
nil
&&
isGoFile
(
f
)
{
err
=
processFile
(
path
,
nil
,
os
.
Stdout
,
false
)
err
=
processFile
(
path
,
nil
,
os
.
Stdout
,
false
)
}
}
...
@@ -225,7 +225,7 @@ func gofmtMain() {
...
@@ -225,7 +225,7 @@ func gofmtMain() {
}
}
}
}
func
diff
(
b1
,
b2
[]
byte
)
(
data
[]
byte
,
err
os
.
E
rror
)
{
func
diff
(
b1
,
b2
[]
byte
)
(
data
[]
byte
,
err
e
rror
)
{
f1
,
err
:=
ioutil
.
TempFile
(
""
,
"gofmt"
)
f1
,
err
:=
ioutil
.
TempFile
(
""
,
"gofmt"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
...
@@ -255,7 +255,7 @@ func diff(b1, b2 []byte) (data []byte, err os.Error) {
...
@@ -255,7 +255,7 @@ func diff(b1, b2 []byte) (data []byte, err os.Error) {
// parse parses src, which was read from filename,
// parse parses src, which was read from filename,
// as a Go source file or statement list.
// as a Go source file or statement list.
func
parse
(
filename
string
,
src
[]
byte
,
stdin
bool
)
(
*
ast
.
File
,
func
(
orig
,
src
[]
byte
)
[]
byte
,
os
.
E
rror
)
{
func
parse
(
filename
string
,
src
[]
byte
,
stdin
bool
)
(
*
ast
.
File
,
func
(
orig
,
src
[]
byte
)
[]
byte
,
e
rror
)
{
// Try as whole source file.
// Try as whole source file.
file
,
err
:=
parser
.
ParseFile
(
fset
,
filename
,
src
,
parserMode
)
file
,
err
:=
parser
.
ParseFile
(
fset
,
filename
,
src
,
parserMode
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -264,7 +264,7 @@ func parse(filename string, src []byte, stdin bool) (*ast.File, func(orig, src [
...
@@ -264,7 +264,7 @@ func parse(filename string, src []byte, stdin bool) (*ast.File, func(orig, src [
// If the error is that the source file didn't begin with a
// If the error is that the source file didn't begin with a
// package line and this is standard input, fall through to
// package line and this is standard input, fall through to
// try as a source fragment. Stop and return on any other error.
// try as a source fragment. Stop and return on any other error.
if
!
stdin
||
!
strings
.
Contains
(
err
.
String
(),
"expected 'package'"
)
{
if
!
stdin
||
!
strings
.
Contains
(
err
.
Error
(),
"expected 'package'"
)
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
@@ -286,7 +286,7 @@ func parse(filename string, src []byte, stdin bool) (*ast.File, func(orig, src [
...
@@ -286,7 +286,7 @@ func parse(filename string, src []byte, stdin bool) (*ast.File, func(orig, src [
// If the error is that the source file didn't begin with a
// If the error is that the source file didn't begin with a
// declaration, fall through to try as a statement list.
// declaration, fall through to try as a statement list.
// Stop and return on any other error.
// Stop and return on any other error.
if
!
strings
.
Contains
(
err
.
String
(),
"expected declaration"
)
{
if
!
strings
.
Contains
(
err
.
Error
(),
"expected declaration"
)
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
...
src/cmd/goinstall/download.go
View file @
44526cdb
...
@@ -8,6 +8,7 @@ package main
...
@@ -8,6 +8,7 @@ package main
import
(
import
(
"bytes"
"bytes"
"errors"
"exec"
"exec"
"fmt"
"fmt"
"http"
"http"
...
@@ -120,7 +121,7 @@ var vcsList = []*vcs{&git, &hg, &bzr, &svn}
...
@@ -120,7 +121,7 @@ var vcsList = []*vcs{&git, &hg, &bzr, &svn}
type
host
struct
{
type
host
struct
{
pattern
*
regexp
.
Regexp
pattern
*
regexp
.
Regexp
getVcs
func
(
repo
,
path
string
)
(
*
vcsMatch
,
os
.
E
rror
)
getVcs
func
(
repo
,
path
string
)
(
*
vcsMatch
,
e
rror
)
}
}
var
knownHosts
=
[]
host
{
var
knownHosts
=
[]
host
{
...
@@ -147,7 +148,7 @@ type vcsMatch struct {
...
@@ -147,7 +148,7 @@ type vcsMatch struct {
prefix
,
repo
string
prefix
,
repo
string
}
}
func
googleVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
googleVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
e
rror
)
{
parts
:=
strings
.
SplitN
(
repo
,
"/"
,
2
)
parts
:=
strings
.
SplitN
(
repo
,
"/"
,
2
)
url
:=
"https://"
+
repo
url
:=
"https://"
+
repo
switch
parts
[
1
]
{
switch
parts
[
1
]
{
...
@@ -158,21 +159,21 @@ func googleVcs(repo, path string) (*vcsMatch, os.Error) {
...
@@ -158,21 +159,21 @@ func googleVcs(repo, path string) (*vcsMatch, os.Error) {
case
"hg"
:
case
"hg"
:
return
&
vcsMatch
{
&
hg
,
repo
,
url
},
nil
return
&
vcsMatch
{
&
hg
,
repo
,
url
},
nil
}
}
return
nil
,
os
.
NewError
(
"unsupported googlecode vcs: "
+
parts
[
1
])
return
nil
,
errors
.
New
(
"unsupported googlecode vcs: "
+
parts
[
1
])
}
}
func
githubVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
githubVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
e
rror
)
{
if
strings
.
HasSuffix
(
repo
,
".git"
)
{
if
strings
.
HasSuffix
(
repo
,
".git"
)
{
return
nil
,
os
.
NewError
(
"path must not include .git suffix"
)
return
nil
,
errors
.
New
(
"path must not include .git suffix"
)
}
}
return
&
vcsMatch
{
&
git
,
repo
,
"http://"
+
repo
+
".git"
},
nil
return
&
vcsMatch
{
&
git
,
repo
,
"http://"
+
repo
+
".git"
},
nil
}
}
func
bitbucketVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
bitbucketVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
e
rror
)
{
const
bitbucketApiUrl
=
"https://api.bitbucket.org/1.0/repositories/"
const
bitbucketApiUrl
=
"https://api.bitbucket.org/1.0/repositories/"
if
strings
.
HasSuffix
(
repo
,
".git"
)
{
if
strings
.
HasSuffix
(
repo
,
".git"
)
{
return
nil
,
os
.
NewError
(
"path must not include .git suffix"
)
return
nil
,
errors
.
New
(
"path must not include .git suffix"
)
}
}
parts
:=
strings
.
SplitN
(
repo
,
"/"
,
2
)
parts
:=
strings
.
SplitN
(
repo
,
"/"
,
2
)
...
@@ -205,16 +206,16 @@ func bitbucketVcs(repo, path string) (*vcsMatch, os.Error) {
...
@@ -205,16 +206,16 @@ func bitbucketVcs(repo, path string) (*vcsMatch, os.Error) {
return
&
vcsMatch
{
&
hg
,
repo
,
"http://"
+
repo
},
nil
return
&
vcsMatch
{
&
hg
,
repo
,
"http://"
+
repo
},
nil
}
}
return
nil
,
os
.
NewError
(
"unsupported bitbucket vcs: "
+
response
.
Vcs
)
return
nil
,
errors
.
New
(
"unsupported bitbucket vcs: "
+
response
.
Vcs
)
}
}
func
launchpadVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
launchpadVcs
(
repo
,
path
string
)
(
*
vcsMatch
,
e
rror
)
{
return
&
vcsMatch
{
&
bzr
,
repo
,
"https://"
+
repo
},
nil
return
&
vcsMatch
{
&
bzr
,
repo
,
"https://"
+
repo
},
nil
}
}
// findPublicRepo checks whether pkg is located at one of
// findPublicRepo checks whether pkg is located at one of
// the supported code hosting sites and, if so, returns a match.
// the supported code hosting sites and, if so, returns a match.
func
findPublicRepo
(
pkg
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
findPublicRepo
(
pkg
string
)
(
*
vcsMatch
,
e
rror
)
{
for
_
,
host
:=
range
knownHosts
{
for
_
,
host
:=
range
knownHosts
{
if
hm
:=
host
.
pattern
.
FindStringSubmatch
(
pkg
);
hm
!=
nil
{
if
hm
:=
host
.
pattern
.
FindStringSubmatch
(
pkg
);
hm
!=
nil
{
return
host
.
getVcs
(
hm
[
1
],
hm
[
2
])
return
host
.
getVcs
(
hm
[
1
],
hm
[
2
])
...
@@ -224,7 +225,7 @@ func findPublicRepo(pkg string) (*vcsMatch, os.Error) {
...
@@ -224,7 +225,7 @@ func findPublicRepo(pkg string) (*vcsMatch, os.Error) {
}
}
// findAnyRepo looks for a vcs suffix in pkg (.git, etc) and returns a match.
// findAnyRepo looks for a vcs suffix in pkg (.git, etc) and returns a match.
func
findAnyRepo
(
pkg
string
)
(
*
vcsMatch
,
os
.
E
rror
)
{
func
findAnyRepo
(
pkg
string
)
(
*
vcsMatch
,
e
rror
)
{
for
_
,
v
:=
range
vcsList
{
for
_
,
v
:=
range
vcsList
{
i
:=
strings
.
Index
(
pkg
+
"/"
,
v
.
suffix
+
"/"
)
i
:=
strings
.
Index
(
pkg
+
"/"
,
v
.
suffix
+
"/"
)
if
i
<
0
{
if
i
<
0
{
...
@@ -272,9 +273,9 @@ func isRemote(pkg string) bool {
...
@@ -272,9 +273,9 @@ func isRemote(pkg string) bool {
}
}
// download checks out or updates pkg from the remote server.
// download checks out or updates pkg from the remote server.
func
download
(
pkg
,
srcDir
string
)
(
public
bool
,
err
os
.
E
rror
)
{
func
download
(
pkg
,
srcDir
string
)
(
public
bool
,
err
e
rror
)
{
if
strings
.
Contains
(
pkg
,
".."
)
{
if
strings
.
Contains
(
pkg
,
".."
)
{
err
=
os
.
NewError
(
"invalid path (contains ..)"
)
err
=
errors
.
New
(
"invalid path (contains ..)"
)
return
return
}
}
m
,
err
:=
findPublicRepo
(
pkg
)
m
,
err
:=
findPublicRepo
(
pkg
)
...
@@ -290,7 +291,7 @@ func download(pkg, srcDir string) (public bool, err os.Error) {
...
@@ -290,7 +291,7 @@ func download(pkg, srcDir string) (public bool, err os.Error) {
}
}
}
}
if
m
==
nil
{
if
m
==
nil
{
err
=
os
.
NewError
(
"cannot download: "
+
pkg
)
err
=
errors
.
New
(
"cannot download: "
+
pkg
)
return
return
}
}
err
=
m
.
checkoutRepo
(
srcDir
,
m
.
prefix
,
m
.
repo
)
err
=
m
.
checkoutRepo
(
srcDir
,
m
.
prefix
,
m
.
repo
)
...
@@ -300,7 +301,7 @@ func download(pkg, srcDir string) (public bool, err os.Error) {
...
@@ -300,7 +301,7 @@ func download(pkg, srcDir string) (public bool, err os.Error) {
// updateRepo gets a list of tags in the repository and
// updateRepo gets a list of tags in the repository and
// checks out the tag closest to the current runtime.Version.
// checks out the tag closest to the current runtime.Version.
// If no matching tag is found, it just updates to tip.
// If no matching tag is found, it just updates to tip.
func
(
v
*
vcs
)
updateRepo
(
dst
string
)
os
.
E
rror
{
func
(
v
*
vcs
)
updateRepo
(
dst
string
)
e
rror
{
if
v
.
tagList
==
""
||
v
.
tagListRe
==
nil
{
if
v
.
tagList
==
""
||
v
.
tagListRe
==
nil
{
// TODO(adg): fix for svn
// TODO(adg): fix for svn
return
run
(
dst
,
nil
,
v
.
cmd
,
v
.
update
)
return
run
(
dst
,
nil
,
v
.
cmd
,
v
.
update
)
...
@@ -382,11 +383,11 @@ func selectTag(goVersion string, tags []string) (match string) {
...
@@ -382,11 +383,11 @@ func selectTag(goVersion string, tags []string) (match string) {
// exists and -u was specified on the command line)
// exists and -u was specified on the command line)
// the repository at tag/branch "release". If there is no
// the repository at tag/branch "release". If there is no
// such tag or branch, it falls back to the repository tip.
// such tag or branch, it falls back to the repository tip.
func
(
vcs
*
vcs
)
checkoutRepo
(
srcDir
,
pkgprefix
,
repo
string
)
os
.
E
rror
{
func
(
vcs
*
vcs
)
checkoutRepo
(
srcDir
,
pkgprefix
,
repo
string
)
e
rror
{
dst
:=
filepath
.
Join
(
srcDir
,
filepath
.
FromSlash
(
pkgprefix
))
dst
:=
filepath
.
Join
(
srcDir
,
filepath
.
FromSlash
(
pkgprefix
))
dir
,
err
:=
os
.
Stat
(
filepath
.
Join
(
dst
,
vcs
.
metadir
))
dir
,
err
:=
os
.
Stat
(
filepath
.
Join
(
dst
,
vcs
.
metadir
))
if
err
==
nil
&&
!
dir
.
IsDirectory
()
{
if
err
==
nil
&&
!
dir
.
IsDirectory
()
{
return
os
.
NewError
(
"not a directory: "
+
dst
)
return
errors
.
New
(
"not a directory: "
+
dst
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
parent
,
_
:=
filepath
.
Split
(
dst
)
parent
,
_
:=
filepath
.
Split
(
dst
)
...
...
src/cmd/goinstall/main.go
View file @
44526cdb
...
@@ -6,6 +6,7 @@ package main
...
@@ -6,6 +6,7 @@ package main
import
(
import
(
"bytes"
"bytes"
"errors"
"exec"
"exec"
"flag"
"flag"
"fmt"
"fmt"
...
@@ -31,7 +32,7 @@ const logfile = "goinstall.log"
...
@@ -31,7 +32,7 @@ const logfile = "goinstall.log"
var
(
var
(
fset
=
token
.
NewFileSet
()
fset
=
token
.
NewFileSet
()
argv0
=
os
.
Args
[
0
]
argv0
=
os
.
Args
[
0
]
errors
=
false
errors
_
=
false
parents
=
make
(
map
[
string
]
string
)
parents
=
make
(
map
[
string
]
string
)
visit
=
make
(
map
[
string
]
status
)
visit
=
make
(
map
[
string
]
status
)
installedPkgs
=
make
(
map
[
string
]
map
[
string
]
bool
)
installedPkgs
=
make
(
map
[
string
]
map
[
string
]
bool
)
...
@@ -67,7 +68,7 @@ func printf(format string, args ...interface{}) {
...
@@ -67,7 +68,7 @@ func printf(format string, args ...interface{}) {
}
}
func
errorf
(
format
string
,
args
...
interface
{})
{
func
errorf
(
format
string
,
args
...
interface
{})
{
errors
=
true
errors
_
=
true
logf
(
format
,
args
...
)
logf
(
format
,
args
...
)
}
}
...
@@ -119,7 +120,7 @@ func main() {
...
@@ -119,7 +120,7 @@ func main() {
install
(
path
,
""
)
install
(
path
,
""
)
}
}
if
errors
{
if
errors
_
{
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
}
}
...
@@ -243,7 +244,7 @@ func install(pkg, parent string) {
...
@@ -243,7 +244,7 @@ func install(pkg, parent string) {
install
(
p
,
pkg
)
install
(
p
,
pkg
)
}
}
}
}
if
errors
{
if
errors
_
{
return
return
}
}
...
@@ -304,17 +305,17 @@ func isStandardPath(s string) bool {
...
@@ -304,17 +305,17 @@ func isStandardPath(s string) bool {
// run runs the command cmd in directory dir with standard input stdin.
// run runs the command cmd in directory dir with standard input stdin.
// If the command fails, run prints the command and output on standard error
// If the command fails, run prints the command and output on standard error
// in addition to returning a non-nil os.Error.
// in addition to returning a non-nil os.Error.
func
run
(
dir
string
,
stdin
[]
byte
,
cmd
...
string
)
os
.
E
rror
{
func
run
(
dir
string
,
stdin
[]
byte
,
cmd
...
string
)
e
rror
{
return
genRun
(
dir
,
stdin
,
cmd
,
false
)
return
genRun
(
dir
,
stdin
,
cmd
,
false
)
}
}
// quietRun is like run but prints nothing on failure unless -v is used.
// quietRun is like run but prints nothing on failure unless -v is used.
func
quietRun
(
dir
string
,
stdin
[]
byte
,
cmd
...
string
)
os
.
E
rror
{
func
quietRun
(
dir
string
,
stdin
[]
byte
,
cmd
...
string
)
e
rror
{
return
genRun
(
dir
,
stdin
,
cmd
,
true
)
return
genRun
(
dir
,
stdin
,
cmd
,
true
)
}
}
// genRun implements run and quietRun.
// genRun implements run and quietRun.
func
genRun
(
dir
string
,
stdin
[]
byte
,
arg
[]
string
,
quiet
bool
)
os
.
E
rror
{
func
genRun
(
dir
string
,
stdin
[]
byte
,
arg
[]
string
,
quiet
bool
)
e
rror
{
cmd
:=
exec
.
Command
(
arg
[
0
],
arg
[
1
:
]
...
)
cmd
:=
exec
.
Command
(
arg
[
0
],
arg
[
1
:
]
...
)
cmd
.
Stdin
=
bytes
.
NewBuffer
(
stdin
)
cmd
.
Stdin
=
bytes
.
NewBuffer
(
stdin
)
cmd
.
Dir
=
dir
cmd
.
Dir
=
dir
...
@@ -329,7 +330,7 @@ func genRun(dir string, stdin []byte, arg []string, quiet bool) os.Error {
...
@@ -329,7 +330,7 @@ func genRun(dir string, stdin []byte, arg []string, quiet bool) os.Error {
os
.
Stderr
.
Write
(
out
)
os
.
Stderr
.
Write
(
out
)
fmt
.
Fprintf
(
os
.
Stderr
,
"--- %s
\n
"
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"--- %s
\n
"
,
err
)
}
}
return
os
.
NewError
(
"running "
+
arg
[
0
]
+
": "
+
err
.
String
())
return
errors
.
New
(
"running "
+
arg
[
0
]
+
": "
+
err
.
Error
())
}
}
return
nil
return
nil
}
}
src/cmd/goinstall/make.go
View file @
44526cdb
...
@@ -8,8 +8,8 @@ package main
...
@@ -8,8 +8,8 @@ package main
import
(
import
(
"bytes"
"bytes"
"errors"
"go/build"
"go/build"
"os"
"path"
// use for import paths
"path"
// use for import paths
"strings"
"strings"
"template"
"template"
...
@@ -18,7 +18,7 @@ import (
...
@@ -18,7 +18,7 @@ import (
// domake builds the package in dir.
// domake builds the package in dir.
// domake generates a standard Makefile and passes it
// domake generates a standard Makefile and passes it
// to make on standard input.
// to make on standard input.
func
domake
(
dir
,
pkg
string
,
tree
*
build
.
Tree
,
isCmd
bool
)
(
err
os
.
E
rror
)
{
func
domake
(
dir
,
pkg
string
,
tree
*
build
.
Tree
,
isCmd
bool
)
(
err
e
rror
)
{
makefile
,
err
:=
makeMakefile
(
dir
,
pkg
,
tree
,
isCmd
)
makefile
,
err
:=
makeMakefile
(
dir
,
pkg
,
tree
,
isCmd
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -36,9 +36,9 @@ func domake(dir, pkg string, tree *build.Tree, isCmd bool) (err os.Error) {
...
@@ -36,9 +36,9 @@ func domake(dir, pkg string, tree *build.Tree, isCmd bool) (err os.Error) {
// makeMakefile computes the standard Makefile for the directory dir
// makeMakefile computes the standard Makefile for the directory dir
// installing as package pkg. It includes all *.go files in the directory
// installing as package pkg. It includes all *.go files in the directory
// except those in package main and those ending in _test.go.
// except those in package main and those ending in _test.go.
func
makeMakefile
(
dir
,
pkg
string
,
tree
*
build
.
Tree
,
isCmd
bool
)
([]
byte
,
os
.
E
rror
)
{
func
makeMakefile
(
dir
,
pkg
string
,
tree
*
build
.
Tree
,
isCmd
bool
)
([]
byte
,
e
rror
)
{
if
!
safeName
(
pkg
)
{
if
!
safeName
(
pkg
)
{
return
nil
,
os
.
NewError
(
"unsafe name: "
+
pkg
)
return
nil
,
errors
.
New
(
"unsafe name: "
+
pkg
)
}
}
targ
:=
pkg
targ
:=
pkg
targDir
:=
tree
.
PkgDir
()
targDir
:=
tree
.
PkgDir
()
...
@@ -56,7 +56,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
...
@@ -56,7 +56,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
isCgo
:=
make
(
map
[
string
]
bool
,
len
(
cgoFiles
))
isCgo
:=
make
(
map
[
string
]
bool
,
len
(
cgoFiles
))
for
_
,
file
:=
range
cgoFiles
{
for
_
,
file
:=
range
cgoFiles
{
if
!
safeName
(
file
)
{
if
!
safeName
(
file
)
{
return
nil
,
os
.
NewError
(
"bad name: "
+
file
)
return
nil
,
errors
.
New
(
"bad name: "
+
file
)
}
}
isCgo
[
file
]
=
true
isCgo
[
file
]
=
true
}
}
...
@@ -64,7 +64,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
...
@@ -64,7 +64,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
goFiles
:=
make
([]
string
,
0
,
len
(
dirInfo
.
GoFiles
))
goFiles
:=
make
([]
string
,
0
,
len
(
dirInfo
.
GoFiles
))
for
_
,
file
:=
range
dirInfo
.
GoFiles
{
for
_
,
file
:=
range
dirInfo
.
GoFiles
{
if
!
safeName
(
file
)
{
if
!
safeName
(
file
)
{
return
nil
,
os
.
NewError
(
"unsafe name: "
+
file
)
return
nil
,
errors
.
New
(
"unsafe name: "
+
file
)
}
}
if
!
isCgo
[
file
]
{
if
!
isCgo
[
file
]
{
goFiles
=
append
(
goFiles
,
file
)
goFiles
=
append
(
goFiles
,
file
)
...
@@ -75,7 +75,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
...
@@ -75,7 +75,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
cgoOFiles
:=
make
([]
string
,
0
,
len
(
dirInfo
.
CFiles
))
cgoOFiles
:=
make
([]
string
,
0
,
len
(
dirInfo
.
CFiles
))
for
_
,
file
:=
range
dirInfo
.
CFiles
{
for
_
,
file
:=
range
dirInfo
.
CFiles
{
if
!
safeName
(
file
)
{
if
!
safeName
(
file
)
{
return
nil
,
os
.
NewError
(
"unsafe name: "
+
file
)
return
nil
,
errors
.
New
(
"unsafe name: "
+
file
)
}
}
// When cgo is in use, C files are compiled with gcc,
// When cgo is in use, C files are compiled with gcc,
// otherwise they're compiled with gc.
// otherwise they're compiled with gc.
...
@@ -88,7 +88,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
...
@@ -88,7 +88,7 @@ func makeMakefile(dir, pkg string, tree *build.Tree, isCmd bool) ([]byte, os.Err
for
_
,
file
:=
range
dirInfo
.
SFiles
{
for
_
,
file
:=
range
dirInfo
.
SFiles
{
if
!
safeName
(
file
)
{
if
!
safeName
(
file
)
{
return
nil
,
os
.
NewError
(
"unsafe name: "
+
file
)
return
nil
,
errors
.
New
(
"unsafe name: "
+
file
)
}
}
oFiles
=
append
(
oFiles
,
file
[
:
len
(
file
)
-
2
]
+
".$O"
)
oFiles
=
append
(
oFiles
,
file
[
:
len
(
file
)
-
2
]
+
".$O"
)
}
}
...
...
src/cmd/gotest/gotest.go
View file @
44526cdb
...
@@ -307,7 +307,7 @@ func doRun(argv []string, returnStdout bool) string {
...
@@ -307,7 +307,7 @@ func doRun(argv []string, returnStdout bool) string {
command
=
"bash"
command
=
"bash"
argv
=
[]
string
{
"bash"
,
"-c"
,
cmd
}
argv
=
[]
string
{
"bash"
,
"-c"
,
cmd
}
}
}
var
err
os
.
E
rror
var
err
e
rror
argv
[
0
],
err
=
exec
.
LookPath
(
argv
[
0
])
argv
[
0
],
err
=
exec
.
LookPath
(
argv
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
Fatalf
(
"can't find %s: %s"
,
command
,
err
)
Fatalf
(
"can't find %s: %s"
,
command
,
err
)
...
...
src/cmd/govet/govet.go
View file @
44526cdb
...
@@ -61,7 +61,7 @@ func main() {
...
@@ -61,7 +61,7 @@ func main() {
}
}
skip
:=
0
skip
:=
0
if
colon
:=
strings
.
LastIndex
(
name
,
":"
);
colon
>
0
{
if
colon
:=
strings
.
LastIndex
(
name
,
":"
);
colon
>
0
{
var
err
os
.
E
rror
var
err
e
rror
skip
,
err
=
strconv
.
Atoi
(
name
[
colon
+
1
:
])
skip
,
err
=
strconv
.
Atoi
(
name
[
colon
+
1
:
])
if
err
!=
nil
{
if
err
!=
nil
{
errorf
(
`illegal format for "Func:N" argument %q; %s`
,
name
,
err
)
errorf
(
`illegal format for "Func:N" argument %q; %s`
,
name
,
err
)
...
@@ -105,7 +105,7 @@ func doFile(name string, reader io.Reader) {
...
@@ -105,7 +105,7 @@ func doFile(name string, reader io.Reader) {
file
.
checkFile
(
name
,
parsedFile
)
file
.
checkFile
(
name
,
parsedFile
)
}
}
func
visit
(
path
string
,
f
*
os
.
FileInfo
,
err
os
.
Error
)
os
.
E
rror
{
func
visit
(
path
string
,
f
*
os
.
FileInfo
,
err
error
)
e
rror
{
if
err
!=
nil
{
if
err
!=
nil
{
errorf
(
"walk error: %s"
,
err
)
errorf
(
"walk error: %s"
,
err
)
return
nil
return
nil
...
...
src/cmd/hgpatch/main.go
View file @
44526cdb
...
@@ -31,7 +31,7 @@ func main() {
...
@@ -31,7 +31,7 @@ func main() {
args
:=
flag
.
Args
()
args
:=
flag
.
Args
()
var
data
[]
byte
var
data
[]
byte
var
err
os
.
E
rror
var
err
e
rror
switch
len
(
args
)
{
switch
len
(
args
)
{
case
0
:
case
0
:
data
,
err
=
ioutil
.
ReadAll
(
os
.
Stdin
)
data
,
err
=
ioutil
.
ReadAll
(
os
.
Stdin
)
...
@@ -189,7 +189,7 @@ func makeParent(name string) {
...
@@ -189,7 +189,7 @@ func makeParent(name string) {
// Copy of os.MkdirAll but adds to undo log after
// Copy of os.MkdirAll but adds to undo log after
// creating a directory.
// creating a directory.
func
mkdirAll
(
path
string
,
perm
uint32
)
os
.
E
rror
{
func
mkdirAll
(
path
string
,
perm
uint32
)
e
rror
{
dir
,
err
:=
os
.
Lstat
(
path
)
dir
,
err
:=
os
.
Lstat
(
path
)
if
err
==
nil
{
if
err
==
nil
{
if
dir
.
IsDirectory
()
{
if
dir
.
IsDirectory
()
{
...
@@ -230,7 +230,7 @@ func mkdirAll(path string, perm uint32) os.Error {
...
@@ -230,7 +230,7 @@ func mkdirAll(path string, perm uint32) os.Error {
}
}
// If err != nil, process the undo log and exit.
// If err != nil, process the undo log and exit.
func
chk
(
err
os
.
E
rror
)
{
func
chk
(
err
e
rror
)
{
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%s
\n
"
,
err
)
fmt
.
Fprintf
(
os
.
Stderr
,
"%s
\n
"
,
err
)
runUndo
()
runUndo
()
...
@@ -239,15 +239,15 @@ func chk(err os.Error) {
...
@@ -239,15 +239,15 @@ func chk(err os.Error) {
}
}
// Undo log
// Undo log
type
undo
func
()
os
.
E
rror
type
undo
func
()
e
rror
var
undoLog
[]
undo
var
undoLog
[]
undo
func
undoRevert
(
name
string
)
{
func
undoRevert
(
name
string
)
{
undoLog
=
append
(
undoLog
,
undo
(
func
()
os
.
E
rror
{
return
hgRevert
(
name
)
}))
undoLog
=
append
(
undoLog
,
undo
(
func
()
e
rror
{
return
hgRevert
(
name
)
}))
}
}
func
undoRm
(
name
string
)
{
undoLog
=
append
(
undoLog
,
undo
(
func
()
os
.
E
rror
{
return
os
.
Remove
(
name
)
}))
}
func
undoRm
(
name
string
)
{
undoLog
=
append
(
undoLog
,
undo
(
func
()
e
rror
{
return
os
.
Remove
(
name
)
}))
}
func
runUndo
()
{
func
runUndo
()
{
for
i
:=
len
(
undoLog
)
-
1
;
i
>=
0
;
i
--
{
for
i
:=
len
(
undoLog
)
-
1
;
i
>=
0
;
i
--
{
...
@@ -258,7 +258,7 @@ func runUndo() {
...
@@ -258,7 +258,7 @@ func runUndo() {
}
}
// hgRoot returns the root directory of the repository.
// hgRoot returns the root directory of the repository.
func
hgRoot
()
(
string
,
os
.
E
rror
)
{
func
hgRoot
()
(
string
,
e
rror
)
{
out
,
err
:=
run
([]
string
{
"hg"
,
"root"
},
nil
)
out
,
err
:=
run
([]
string
{
"hg"
,
"root"
},
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -276,7 +276,7 @@ func hgIncoming() bool {
...
@@ -276,7 +276,7 @@ func hgIncoming() bool {
// hgModified returns a list of the modified files in the
// hgModified returns a list of the modified files in the
// repository.
// repository.
func
hgModified
()
([]
string
,
os
.
E
rror
)
{
func
hgModified
()
([]
string
,
e
rror
)
{
out
,
err
:=
run
([]
string
{
"hg"
,
"status"
,
"-n"
},
nil
)
out
,
err
:=
run
([]
string
{
"hg"
,
"status"
,
"-n"
},
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -285,33 +285,33 @@ func hgModified() ([]string, os.Error) {
...
@@ -285,33 +285,33 @@ func hgModified() ([]string, os.Error) {
}
}
// hgAdd adds name to the repository.
// hgAdd adds name to the repository.
func
hgAdd
(
name
string
)
os
.
E
rror
{
func
hgAdd
(
name
string
)
e
rror
{
_
,
err
:=
run
([]
string
{
"hg"
,
"add"
,
name
},
nil
)
_
,
err
:=
run
([]
string
{
"hg"
,
"add"
,
name
},
nil
)
return
err
return
err
}
}
// hgRemove removes name from the repository.
// hgRemove removes name from the repository.
func
hgRemove
(
name
string
)
os
.
E
rror
{
func
hgRemove
(
name
string
)
e
rror
{
_
,
err
:=
run
([]
string
{
"hg"
,
"rm"
,
name
},
nil
)
_
,
err
:=
run
([]
string
{
"hg"
,
"rm"
,
name
},
nil
)
return
err
return
err
}
}
// hgRevert reverts name.
// hgRevert reverts name.
func
hgRevert
(
name
string
)
os
.
E
rror
{
func
hgRevert
(
name
string
)
e
rror
{
_
,
err
:=
run
([]
string
{
"hg"
,
"revert"
,
name
},
nil
)
_
,
err
:=
run
([]
string
{
"hg"
,
"revert"
,
name
},
nil
)
return
err
return
err
}
}
// hgCopy copies src to dst in the repository.
// hgCopy copies src to dst in the repository.
// Note that the argument order matches io.Copy, not "hg cp".
// Note that the argument order matches io.Copy, not "hg cp".
func
hgCopy
(
dst
,
src
string
)
os
.
E
rror
{
func
hgCopy
(
dst
,
src
string
)
e
rror
{
_
,
err
:=
run
([]
string
{
"hg"
,
"cp"
,
src
,
dst
},
nil
)
_
,
err
:=
run
([]
string
{
"hg"
,
"cp"
,
src
,
dst
},
nil
)
return
err
return
err
}
}
// hgRename renames src to dst in the repository.
// hgRename renames src to dst in the repository.
// Note that the argument order matches io.Copy, not "hg mv".
// Note that the argument order matches io.Copy, not "hg mv".
func
hgRename
(
dst
,
src
string
)
os
.
E
rror
{
func
hgRename
(
dst
,
src
string
)
e
rror
{
_
,
err
:=
run
([]
string
{
"hg"
,
"mv"
,
src
,
dst
},
nil
)
_
,
err
:=
run
([]
string
{
"hg"
,
"mv"
,
src
,
dst
},
nil
)
return
err
return
err
}
}
...
@@ -326,7 +326,7 @@ var lookPathCache = make(map[string]string)
...
@@ -326,7 +326,7 @@ var lookPathCache = make(map[string]string)
// run runs the command argv, resolving argv[0] if necessary by searching $PATH.
// run runs the command argv, resolving argv[0] if necessary by searching $PATH.
// It provides input on standard input to the command.
// It provides input on standard input to the command.
func
run
(
argv
[]
string
,
input
[]
byte
)
(
out
string
,
err
os
.
E
rror
)
{
func
run
(
argv
[]
string
,
input
[]
byte
)
(
out
string
,
err
e
rror
)
{
if
len
(
argv
)
<
1
{
if
len
(
argv
)
<
1
{
return
""
,
&
runError
{
dup
(
argv
),
os
.
EINVAL
}
return
""
,
&
runError
{
dup
(
argv
),
os
.
EINVAL
}
}
}
...
@@ -354,7 +354,7 @@ func run(argv []string, input []byte) (out string, err os.Error) {
...
@@ -354,7 +354,7 @@ func run(argv []string, input []byte) (out string, err os.Error) {
// A runError represents an error that occurred while running a command.
// A runError represents an error that occurred while running a command.
type
runError
struct
{
type
runError
struct
{
cmd
[]
string
cmd
[]
string
err
os
.
E
rror
err
e
rror
}
}
func
(
e
*
runError
)
String
()
string
{
return
strings
.
Join
(
e
.
cmd
,
" "
)
+
": "
+
e
.
err
.
String
()
}
func
(
e
*
runError
)
Error
()
string
{
return
strings
.
Join
(
e
.
cmd
,
" "
)
+
": "
+
e
.
err
.
Error
()
}
test/chan/goroutines.go
View file @
44526cdb
...
@@ -21,7 +21,7 @@ func f(left, right chan int) {
...
@@ -21,7 +21,7 @@ func f(left, right chan int) {
func
main
()
{
func
main
()
{
var
n
=
10000
var
n
=
10000
if
len
(
os
.
Args
)
>
1
{
if
len
(
os
.
Args
)
>
1
{
var
err
os
.
E
rror
var
err
e
rror
n
,
err
=
strconv
.
Atoi
(
os
.
Args
[
1
])
n
,
err
=
strconv
.
Atoi
(
os
.
Args
[
1
])
if
err
!=
nil
{
if
err
!=
nil
{
print
(
"bad arg
\n
"
)
print
(
"bad arg
\n
"
)
...
...
test/env.go
View file @
44526cdb
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
func
main
()
{
func
main
()
{
ga
,
e0
:=
os
.
Getenverror
(
"GOARCH"
)
ga
,
e0
:=
os
.
Getenverror
(
"GOARCH"
)
if
e0
!=
nil
{
if
e0
!=
nil
{
print
(
"$GOARCH: "
,
e0
.
String
(),
"
\n
"
)
print
(
"$GOARCH: "
,
e0
.
Error
(),
"
\n
"
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
if
ga
!=
runtime
.
GOARCH
{
if
ga
!=
runtime
.
GOARCH
{
...
@@ -23,7 +23,7 @@ func main() {
...
@@ -23,7 +23,7 @@ func main() {
}
}
xxx
,
e1
:=
os
.
Getenverror
(
"DOES_NOT_EXIST"
)
xxx
,
e1
:=
os
.
Getenverror
(
"DOES_NOT_EXIST"
)
if
e1
!=
os
.
ENOENV
{
if
e1
!=
os
.
ENOENV
{
print
(
"$DOES_NOT_EXIST="
,
xxx
,
"; err = "
,
e1
.
String
(),
"
\n
"
)
print
(
"$DOES_NOT_EXIST="
,
xxx
,
"; err = "
,
e1
.
Error
(),
"
\n
"
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
}
}
test/fixedbugs/bug243.go
View file @
44526cdb
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
package
main
package
main
import
"
o
s"
import
"
error
s"
// Issue 481: closures and var declarations
// Issue 481: closures and var declarations
// with multiple variables assigned from one
// with multiple variables assigned from one
...
@@ -22,7 +22,7 @@ func main() {
...
@@ -22,7 +22,7 @@ func main() {
}
}
}()
}()
var
conn
,
_
=
Dial
(
"tcp"
,
""
,
listen
.
Addr
()
.
String
())
var
conn
,
_
=
Dial
(
"tcp"
,
""
,
listen
.
Addr
()
.
Error
())
_
=
conn
_
=
conn
}
}
...
@@ -37,8 +37,8 @@ func Listen(x, y string) (T, string) {
...
@@ -37,8 +37,8 @@ func Listen(x, y string) (T, string) {
return
global
,
y
return
global
,
y
}
}
func
(
t
T
)
Addr
()
os
.
E
rror
{
func
(
t
T
)
Addr
()
e
rror
{
return
os
.
NewError
(
"stringer"
)
return
errors
.
New
(
"stringer"
)
}
}
func
(
t
T
)
Accept
()
(
int
,
string
)
{
func
(
t
T
)
Accept
()
(
int
,
string
)
{
...
...
test/fixedbugs/bug262.go
View file @
44526cdb
...
@@ -18,9 +18,9 @@ func f() string {
...
@@ -18,9 +18,9 @@ func f() string {
return
"abc"
return
"abc"
}
}
func
g
()
*
os
.
E
rror
{
func
g
()
*
e
rror
{
trace
+=
"g"
trace
+=
"g"
var
x
os
.
E
rror
var
x
e
rror
return
&
x
return
&
x
}
}
...
@@ -35,7 +35,6 @@ func i() *int {
...
@@ -35,7 +35,6 @@ func i() *int {
return
&
i
return
&
i
}
}
func
main
()
{
func
main
()
{
m
:=
make
(
map
[
string
]
int
)
m
:=
make
(
map
[
string
]
int
)
m
[
f
()],
*
g
()
=
strconv
.
Atoi
(
h
())
m
[
f
()],
*
g
()
=
strconv
.
Atoi
(
h
())
...
@@ -43,7 +42,7 @@ func main() {
...
@@ -43,7 +42,7 @@ func main() {
println
(
"BUG"
,
m
[
"abc"
],
trace
)
println
(
"BUG"
,
m
[
"abc"
],
trace
)
panic
(
"fail"
)
panic
(
"fail"
)
}
}
mm
:=
make
(
map
[
string
]
os
.
E
rror
)
mm
:=
make
(
map
[
string
]
e
rror
)
trace
=
""
trace
=
""
mm
[
"abc"
]
=
os
.
EINVAL
mm
[
"abc"
]
=
os
.
EINVAL
*
i
(),
mm
[
f
()]
=
strconv
.
Atoi
(
h
())
*
i
(),
mm
[
f
()]
=
strconv
.
Atoi
(
h
())
...
...
test/fixedbugs/bug286.go
View file @
44526cdb
...
@@ -12,16 +12,14 @@ type I interface {
...
@@ -12,16 +12,14 @@ type I interface {
f
()
f
()
}
}
var
callee
string
var
callee
string
var
error
bool
var
error
_
bool
type
T
int
type
T
int
func
(
t
*
T
)
f
()
{
callee
=
"f"
}
func
(
t
*
T
)
f
()
{
callee
=
"f"
}
func
(
i
*
T
)
g
()
{
callee
=
"g"
}
func
(
i
*
T
)
g
()
{
callee
=
"g"
}
// test1 and test2 are the same except that in the interface J
// test1 and test2 are the same except that in the interface J
// the entries are swapped. test2 and test3 are the same except
// the entries are swapped. test2 and test3 are the same except
// that in test3 the interface J is declared outside the function.
// that in test3 the interface J is declared outside the function.
...
@@ -36,11 +34,10 @@ func test1(x I) {
...
@@ -36,11 +34,10 @@ func test1(x I) {
x
.
(
J
)
.
f
()
x
.
(
J
)
.
f
()
if
callee
!=
"f"
{
if
callee
!=
"f"
{
println
(
"test1 called"
,
callee
)
println
(
"test1 called"
,
callee
)
error
=
true
error
_
=
true
}
}
}
}
func
test2
(
x
I
)
{
func
test2
(
x
I
)
{
type
J
interface
{
type
J
interface
{
g
()
g
()
...
@@ -49,11 +46,10 @@ func test2(x I) {
...
@@ -49,11 +46,10 @@ func test2(x I) {
x
.
(
J
)
.
f
()
x
.
(
J
)
.
f
()
if
callee
!=
"f"
{
if
callee
!=
"f"
{
println
(
"test2 called"
,
callee
)
println
(
"test2 called"
,
callee
)
error
=
true
error
_
=
true
}
}
}
}
type
J
interface
{
type
J
interface
{
g
()
g
()
I
I
...
@@ -63,7 +59,7 @@ func test3(x I) {
...
@@ -63,7 +59,7 @@ func test3(x I) {
x
.
(
J
)
.
f
()
x
.
(
J
)
.
f
()
if
callee
!=
"f"
{
if
callee
!=
"f"
{
println
(
"test3 called"
,
callee
)
println
(
"test3 called"
,
callee
)
error
=
true
error
_
=
true
}
}
}
}
...
@@ -72,7 +68,7 @@ func main() {
...
@@ -72,7 +68,7 @@ func main() {
test1
(
x
)
test1
(
x
)
test2
(
x
)
test2
(
x
)
test3
(
x
)
test3
(
x
)
if
error
{
if
error
_
{
panic
(
"wrong method called"
)
panic
(
"wrong method called"
)
}
}
}
}
...
...
test/fixedbugs/bug326.go
View file @
44526cdb
...
@@ -6,36 +6,34 @@
...
@@ -6,36 +6,34 @@
package
p
package
p
import
"os"
func
f
()
(
_
int
,
err
error
)
{
func
f
()
(
_
int
,
err
os
.
Error
)
{
return
return
}
}
func
g
()
(
x
int
,
_
os
.
E
rror
)
{
func
g
()
(
x
int
,
_
e
rror
)
{
return
return
}
}
func
h
()
(
_
int
,
_
os
.
E
rror
)
{
func
h
()
(
_
int
,
_
e
rror
)
{
return
return
}
}
func
i
()
(
int
,
os
.
E
rror
)
{
func
i
()
(
int
,
e
rror
)
{
return
// ERROR "not enough arguments to return"
return
// ERROR "not enough arguments to return"
}
}
func
f1
()
(
_
int
,
err
os
.
E
rror
)
{
func
f1
()
(
_
int
,
err
e
rror
)
{
return
1
,
nil
return
1
,
nil
}
}
func
g1
()
(
x
int
,
_
os
.
E
rror
)
{
func
g1
()
(
x
int
,
_
e
rror
)
{
return
1
,
nil
return
1
,
nil
}
}
func
h1
()
(
_
int
,
_
os
.
E
rror
)
{
func
h1
()
(
_
int
,
_
e
rror
)
{
return
1
,
nil
return
1
,
nil
}
}
func
ii
()
(
int
,
os
.
E
rror
)
{
func
ii
()
(
int
,
e
rror
)
{
return
1
,
nil
return
1
,
nil
}
}
test/fixedbugs/bug331.go
View file @
44526cdb
...
@@ -6,22 +6,22 @@
...
@@ -6,22 +6,22 @@
package
main
package
main
import
"
os
"
import
"
io
"
func
f
()
(
_
string
,
x
float64
,
err
os
.
E
rror
)
{
func
f
()
(
_
string
,
x
float64
,
err
e
rror
)
{
return
return
}
}
func
g
()
(
_
string
,
x
float64
,
err
os
.
E
rror
)
{
func
g
()
(
_
string
,
x
float64
,
err
e
rror
)
{
return
"hello"
,
3.14
,
os
.
EOF
return
"hello"
,
3.14
,
io
.
EOF
}
}
var
_
func
()
(
string
,
float64
,
os
.
E
rror
)
=
f
var
_
func
()
(
string
,
float64
,
e
rror
)
=
f
var
_
func
()
(
string
,
float64
,
os
.
E
rror
)
=
g
var
_
func
()
(
string
,
float64
,
e
rror
)
=
g
func
main
()
{
func
main
()
{
x
,
y
,
z
:=
g
()
x
,
y
,
z
:=
g
()
if
x
!=
"hello"
||
y
!=
3.14
||
z
!=
os
.
EOF
{
if
x
!=
"hello"
||
y
!=
3.14
||
z
!=
io
.
EOF
{
println
(
"wrong"
,
x
,
len
(
x
),
y
,
z
)
println
(
"wrong"
,
x
,
len
(
x
),
y
,
z
)
}
}
}
}
...
...
test/fixedbugs/bug354.go
View file @
44526cdb
...
@@ -9,12 +9,8 @@
...
@@ -9,12 +9,8 @@
package
main
package
main
import
(
"os"
)
type
Inner
struct
{
type
Inner
struct
{
F
func
()
os
.
E
rror
F
func
()
e
rror
}
}
type
Outer
struct
{
type
Outer
struct
{
...
@@ -23,4 +19,4 @@ type Outer struct {
...
@@ -23,4 +19,4 @@ type Outer struct {
// calls makeclosure twice on same closure
// calls makeclosure twice on same closure
var
Foo
=
Outer
{[]
Inner
{
Inner
{
func
()
os
.
Error
{
return
nil
}}}}
var
Foo
=
Outer
{[]
Inner
{
Inner
{
func
()
error
{
return
nil
}}}}
test/func2.go
View file @
44526cdb
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
main
package
main
import
os
"os"
type
t1
int
type
t1
int
type
t2
int
type
t2
int
...
@@ -23,7 +22,7 @@ func f8(os int) int
...
@@ -23,7 +22,7 @@ func f8(os int) int
func
f9
(
os
int
)
int
{
func
f9
(
os
int
)
int
{
return
os
return
os
}
}
func
f10
(
err
os
.
Error
)
os
.
E
rror
{
func
f10
(
err
error
)
e
rror
{
return
err
return
err
}
}
func
f11
(
t1
string
)
string
{
func
f11
(
t1
string
)
string
{
...
...
test/garbage/parser.go
View file @
44526cdb
...
@@ -66,7 +66,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
...
@@ -66,7 +66,7 @@ func parseDir(dirpath string) map[string]*ast.Package {
// get package AST
// get package AST
pkgs
,
err
:=
parser
.
ParseDir
(
token
.
NewFileSet
(),
dirpath
,
filter
,
parser
.
ParseComments
)
pkgs
,
err
:=
parser
.
ParseDir
(
token
.
NewFileSet
(),
dirpath
,
filter
,
parser
.
ParseComments
)
if
err
!=
nil
{
if
err
!=
nil
{
println
(
"parse"
,
dirpath
,
err
.
String
())
println
(
"parse"
,
dirpath
,
err
.
Error
())
panic
(
"fail"
)
panic
(
"fail"
)
}
}
return
pkgs
return
pkgs
...
...
test/recover2.go
View file @
44526cdb
...
@@ -11,10 +11,7 @@
...
@@ -11,10 +11,7 @@
package
main
package
main
import
(
import
"strings"
"os"
"strings"
)
var
x
=
make
([]
byte
,
10
)
var
x
=
make
([]
byte
,
10
)
...
@@ -33,7 +30,7 @@ func mustRecover(s string) {
...
@@ -33,7 +30,7 @@ func mustRecover(s string) {
if
v
==
nil
{
if
v
==
nil
{
panic
(
"expected panic"
)
panic
(
"expected panic"
)
}
}
if
e
:=
v
.
(
os
.
Error
)
.
String
();
strings
.
Index
(
e
,
s
)
<
0
{
if
e
:=
v
.
(
error
)
.
Error
();
strings
.
Index
(
e
,
s
)
<
0
{
panic
(
"want: "
+
s
+
"; have: "
+
e
)
panic
(
"want: "
+
s
+
"; have: "
+
e
)
}
}
}
}
...
...
test/recover3.go
View file @
44526cdb
...
@@ -35,7 +35,7 @@ func check(name string, f func(), err string) {
...
@@ -35,7 +35,7 @@ func check(name string, f func(), err string) {
println
(
name
,
"panicked but not with runtime.Error"
)
println
(
name
,
"panicked but not with runtime.Error"
)
return
return
}
}
s
:=
runt
.
String
()
s
:=
runt
.
Error
()
if
strings
.
Index
(
s
,
err
)
<
0
{
if
strings
.
Index
(
s
,
err
)
<
0
{
bug
()
bug
()
println
(
name
,
"panicked with"
,
s
,
"not"
,
err
)
println
(
name
,
"panicked with"
,
s
,
"not"
,
err
)
...
...
test/zerodivide.go
View file @
44526cdb
...
@@ -158,10 +158,10 @@ var errorTests = []ErrorTest{
...
@@ -158,10 +158,10 @@ var errorTests = []ErrorTest{
ErrorTest
{
"complex128 1/0"
,
func
()
{
use
(
e128
/
d128
)
},
""
},
ErrorTest
{
"complex128 1/0"
,
func
()
{
use
(
e128
/
d128
)
},
""
},
}
}
func
error
(
fn
func
())
(
error
string
)
{
func
error
_
(
fn
func
())
(
error
string
)
{
defer
func
()
{
defer
func
()
{
if
e
:=
recover
();
e
!=
nil
{
if
e
:=
recover
();
e
!=
nil
{
error
=
e
.
(
runtime
.
Error
)
.
String
()
error
=
e
.
(
runtime
.
Error
)
.
Error
()
}
}
}()
}()
fn
()
fn
()
...
@@ -196,7 +196,7 @@ func main() {
...
@@ -196,7 +196,7 @@ func main() {
if
t
.
err
!=
""
{
if
t
.
err
!=
""
{
continue
continue
}
}
err
:=
error
(
t
.
fn
)
err
:=
error
_
(
t
.
fn
)
switch
{
switch
{
case
t
.
err
==
""
&&
err
==
""
:
case
t
.
err
==
""
&&
err
==
""
:
// fine
// fine
...
...
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