all: update code to satisfy golint
This silences all warnings except those about documentation.
Change-Id: I1d61bf871dcfd6d95b53f66d9e9378f4f648c3a0
Reviewed-on: https://go-review.googlesource.com/20464
Reviewed-by: Dmitri Shuralyov <shurcool@gmail.com>
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/database/database.go b/database/database.go
index 584a027..16abbac 100644
--- a/database/database.go
+++ b/database/database.go
@@ -114,11 +114,11 @@
IdleTimeout: *redisIdleTimeout,
}
- if c := pool.Get(); c.Err() != nil {
+ c := pool.Get()
+ if c.Err() != nil {
return nil, c.Err()
- } else {
- c.Close()
}
+ c.Close()
return &Database{Pool: pool}, nil
}
diff --git a/gddo-admin/reindex.go b/gddo-admin/reindex.go
index 44280f2..3c0210f 100644
--- a/gddo-admin/reindex.go
+++ b/gddo-admin/reindex.go
@@ -57,7 +57,7 @@
}
var n int
err = db.Do(func(pi *database.PackageInfo) error {
- n += 1
+ n++
fix(pi.PDoc)
return db.Put(pi.PDoc, time.Time{}, false)
})
diff --git a/gddo-server/graph.go b/gddo-server/graph.go
index e5bc488..9a3f9c7 100644
--- a/gddo-server/graph.go
+++ b/gddo-server/graph.go
@@ -39,10 +39,10 @@
}
p := out.Bytes()
- if i := bytes.Index(p, []byte("<svg")); i < 0 {
+ i := bytes.Index(p, []byte("<svg"))
+ if i < 0 {
return nil, errors.New("<svg not found")
- } else {
- p = p[i:]
}
+ p = p[i:]
return p, nil
}
diff --git a/gddo-server/template.go b/gddo-server/template.go
index 272dbf0..c234d3f 100644
--- a/gddo-server/template.go
+++ b/gddo-server/template.go
@@ -97,9 +97,8 @@
if pos.Line == 0 || pdoc.LineFmt == "" || pdoc.Files[pos.File].URL == "" {
if textOnlyOK {
return htemp.HTML(htemp.HTMLEscapeString(text))
- } else {
- return ""
}
+ return ""
}
return htemp.HTML(fmt.Sprintf(`<a title="View Source" href="%s">%s</a>`,
htemp.HTMLEscapeString(fmt.Sprintf(pdoc.LineFmt, pdoc.Files[pos.File].URL, pos.Line)),
diff --git a/gosrc/github.go b/gosrc/github.go
index 4a37388..5ae969f 100644
--- a/gosrc/github.go
+++ b/gosrc/github.go
@@ -291,7 +291,7 @@
Files map[string]struct {
Content string
}
- HtmlUrl string `json:"html_url"`
+ HTMLURL string `json:"html_url"`
History []struct {
Version string
}
@@ -317,19 +317,19 @@
files = append(files, &File{
Name: name,
Data: []byte(file.Content),
- BrowseURL: gist.HtmlUrl + "#file-" + strings.Replace(name, ".", "-", -1),
+ BrowseURL: gist.HTMLURL + "#file-" + strings.Replace(name, ".", "-", -1),
})
}
}
return &Directory{
- BrowseURL: gist.HtmlUrl,
+ BrowseURL: gist.HTMLURL,
Etag: commit,
Files: files,
LineFmt: "%s-L%d",
ProjectName: match["gist"],
ProjectRoot: expand("gist.github.com/{gist}.git", match),
- ProjectURL: gist.HtmlUrl,
+ ProjectURL: gist.HTMLURL,
Subdirectories: nil,
VCS: "git",
}, nil
diff --git a/httputil/buster.go b/httputil/buster.go
index 9bbf243..beab151 100644
--- a/httputil/buster.go
+++ b/httputil/buster.go
@@ -48,7 +48,7 @@
return r
}
-// Token returns the cache busting token for path. If the token is not already
+// Get returns the cache busting token for path. If the token is not already
// cached, Get issues a HEAD request on handler and uses the response ETag and
// Last-Modified headers to compute a token.
func (cb *CacheBusters) Get(path string) string {
diff --git a/httputil/header/header.go b/httputil/header/header.go
index bd30b33..0f1572e 100644
--- a/httputil/header/header.go
+++ b/httputil/header/header.go
@@ -162,6 +162,7 @@
return
}
+// AcceptSpec describes an Accept* header.
type AcceptSpec struct {
Value string
Q float64
@@ -280,14 +281,14 @@
case escape:
escape = false
p[j] = b
- j += 1
+ j++
case b == '\\':
escape = true
case b == '"':
return string(p[:j]), s[i+1:]
default:
p[j] = b
- j += 1
+ j++
}
}
return "", ""
diff --git a/httputil/httputil.go b/httputil/httputil.go
index b077edf..a03717c 100644
--- a/httputil/httputil.go
+++ b/httputil/httputil.go
@@ -20,4 +20,6 @@
return s
}
+// Error defines a type for a function that accepts a ResponseWriter for
+// a Request with the HTTP status code and error.
type Error func(w http.ResponseWriter, r *http.Request, status int, err error)
diff --git a/httputil/respbuf.go b/httputil/respbuf.go
index 8641c0f..051af21 100644
--- a/httputil/respbuf.go
+++ b/httputil/respbuf.go
@@ -12,20 +12,25 @@
"strconv"
)
+// ResponseBuffer is the current response being composed by its owner.
+// It implements http.ResponseWriter and io.WriterTo.
type ResponseBuffer struct {
buf bytes.Buffer
status int
header http.Header
}
+// Write implements the http.ResponseWriter interface.
func (rb *ResponseBuffer) Write(p []byte) (int, error) {
return rb.buf.Write(p)
}
+// WriteHeader implements the http.ResponseWriter interface.
func (rb *ResponseBuffer) WriteHeader(status int) {
rb.status = status
}
+// Header implements the http.ResponseWriter interface.
func (rb *ResponseBuffer) Header() http.Header {
if rb.header == nil {
rb.header = make(http.Header)
@@ -33,6 +38,7 @@
return rb.header
}
+// WriteTo implements the io.WriterTo interface.
func (rb *ResponseBuffer) WriteTo(w http.ResponseWriter) error {
for k, v := range rb.header {
w.Header()[k] = v
diff --git a/httputil/transport.go b/httputil/transport.go
index 4823a87..2988a3c 100644
--- a/httputil/transport.go
+++ b/httputil/transport.go
@@ -96,11 +96,11 @@
}
// CancelRequest cancels an in-flight request by closing its connection.
-func (c *AuthTransport) CancelRequest(req *http.Request) {
+func (t *AuthTransport) CancelRequest(req *http.Request) {
type canceler interface {
CancelRequest(req *http.Request)
}
- if cr, ok := c.base().(canceler); ok {
+ if cr, ok := t.base().(canceler); ok {
cr.CancelRequest(req)
}
}
diff --git a/lintapp/main.go b/lintapp/main.go
index 14fc690..fbfba87 100644
--- a/lintapp/main.go
+++ b/lintapp/main.go
@@ -236,7 +236,7 @@
for i := range f.Problems {
if f.Problems[i].Confidence >= minConfidence {
f.Problems[j] = f.Problems[i]
- j += 1
+ j++
}
}
f.Problems = f.Problems[:j]