From b0d8f6a5c18d3f040c3ef048c0c9992309e50433 Mon Sep 17 00:00:00 2001 From: Andy Finkenstadt Date: Mon, 13 Jul 2015 18:37:03 -0700 Subject: [PATCH] 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 Reviewed-by: Andrew Gerrand --- database/database.go | 6 +++--- gddo-admin/reindex.go | 2 +- gddo-server/graph.go | 6 +++--- gddo-server/template.go | 3 +-- gosrc/github.go | 8 ++++---- httputil/buster.go | 2 +- httputil/header/header.go | 5 +++-- httputil/httputil.go | 2 ++ httputil/respbuf.go | 6 ++++++ httputil/transport.go | 4 ++-- lintapp/main.go | 2 +- 11 files changed, 27 insertions(+), 19 deletions(-) diff --git a/database/database.go b/database/database.go index 584a0274..16abbaca 100644 --- a/database/database.go +++ b/database/database.go @@ -114,11 +114,11 @@ func New() (*Database, error) { 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 44280f24..3c0210f3 100644 --- a/gddo-admin/reindex.go +++ b/gddo-admin/reindex.go @@ -57,7 +57,7 @@ func reindex(c *command) { } 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 e5bc4887..9a3f9c72 100644 --- a/gddo-server/graph.go +++ b/gddo-server/graph.go @@ -39,10 +39,10 @@ func renderGraph(pdoc *doc.Package, pkgs []database.Package, edges [][2]int) ([] } p := out.Bytes() - if i := bytes.Index(p, []byte("%s`, htemp.HTMLEscapeString(fmt.Sprintf(pdoc.LineFmt, pdoc.Files[pos.File].URL, pos.Line)), diff --git a/gosrc/github.go b/gosrc/github.go index 4a37388c..5ae969f3 100644 --- a/gosrc/github.go +++ b/gosrc/github.go @@ -291,7 +291,7 @@ func getGistDir(client *http.Client, match map[string]string, savedEtag string) Files map[string]struct { Content string } - HtmlUrl string `json:"html_url"` + HTMLURL string `json:"html_url"` History []struct { Version string } @@ -317,19 +317,19 @@ func getGistDir(client *http.Client, match map[string]string, savedEtag string) 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 9bbf2439..beab151a 100644 --- a/httputil/buster.go +++ b/httputil/buster.go @@ -48,7 +48,7 @@ func sanitizeTokenRune(r rune) rune { 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 bd30b336..0f1572e3 100644 --- a/httputil/header/header.go +++ b/httputil/header/header.go @@ -162,6 +162,7 @@ func ParseValueAndParams(header http.Header, key string) (value string, params m return } +// AcceptSpec describes an Accept* header. type AcceptSpec struct { Value string Q float64 @@ -280,14 +281,14 @@ func expectTokenOrQuoted(s string) (value string, rest string) { 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 b077edf3..a03717c0 100644 --- a/httputil/httputil.go +++ b/httputil/httputil.go @@ -20,4 +20,6 @@ func StripPort(s string) string { 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 8641c0f4..051af211 100644 --- a/httputil/respbuf.go +++ b/httputil/respbuf.go @@ -12,20 +12,25 @@ import ( "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 @@ func (rb *ResponseBuffer) Header() http.Header { 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 4823a87d..2988a3c2 100644 --- a/httputil/transport.go +++ b/httputil/transport.go @@ -96,11 +96,11 @@ func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error) { } // 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 14fc6906..fbfba873 100644 --- a/lintapp/main.go +++ b/lintapp/main.go @@ -236,7 +236,7 @@ func filterByConfidence(r *http.Request, pkg *lintPackage) { 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]