Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
all: update code to satisfy golint
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
afinkenstadt authored and adg committed Mar 10, 2016
1 parent d5e2232 commit b0d8f6a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 19 deletions.
6 changes: 3 additions & 3 deletions database/database.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion gddo-admin/reindex.go
Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions gddo-server/graph.go
Expand Up @@ -39,10 +39,10 @@ func renderGraph(pdoc *doc.Package, pkgs []database.Package, edges [][2]int) ([]
}

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
}
3 changes: 1 addition & 2 deletions gddo-server/template.go
Expand Up @@ -97,9 +97,8 @@ func (pdoc *tdoc) SourceLink(pos doc.Pos, text string, textOnlyOK bool) htemp.HT
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)),
Expand Down
8 changes: 4 additions & 4 deletions gosrc/github.go
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion httputil/buster.go
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions httputil/header/header.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 "", ""
Expand Down
2 changes: 2 additions & 0 deletions httputil/httputil.go
Expand Up @@ -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)
6 changes: 6 additions & 0 deletions httputil/respbuf.go
Expand Up @@ -12,27 +12,33 @@ 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)
}
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
Expand Down
4 changes: 2 additions & 2 deletions httputil/transport.go
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lintapp/main.go
Expand Up @@ -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]
Expand Down

0 comments on commit b0d8f6a

Please sign in to comment.