From ad22c3f2997adf6dc548814d1990edb28bdabfc2 Mon Sep 17 00:00:00 2001 From: Sourcegraph Bot Date: Thu, 12 Dec 2019 18:15:09 +0000 Subject: [PATCH 1/2] tidy: convert Fprintf to Fprintln when possible --- cmd/frontend/graphqlbackend/search_pagination_test.go | 4 ++-- cmd/server/shared/postgres.go | 4 ++-- internal/debugserver/expvar.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/frontend/graphqlbackend/search_pagination_test.go b/cmd/frontend/graphqlbackend/search_pagination_test.go index 8f13853554d5..83f931c9035f 100644 --- a/cmd/frontend/graphqlbackend/search_pagination_test.go +++ b/cmd/frontend/graphqlbackend/search_pagination_test.go @@ -47,12 +47,12 @@ func TestSearchPagination_sliceSearchResults(t *testing.T) { } format := func(r slicedSearchResults) string { var b bytes.Buffer - fmt.Fprintf(&b, "results:\n") + fmt.Fprintln(&b, "results:") for i, result := range r.results { fm, _ := result.ToFileMatch() fmt.Fprintf(&b, " [%d] %s %s\n", i, fm.Repo.Name, fm.JPath) } - fmt.Fprintf(&b, "common.repos:\n") + fmt.Fprintln(&b, "common.repos:") for i, r := range r.common.repos { fmt.Fprintf(&b, " [%d] %s\n", i, r.Name) } diff --git a/cmd/server/shared/postgres.go b/cmd/server/shared/postgres.go index e9c4879b959a..a45aa010e9d2 100644 --- a/cmd/server/shared/postgres.go +++ b/cmd/server/shared/postgres.go @@ -137,8 +137,8 @@ func maybeUpgradePostgres(path, newVersion string) (err error) { hostDataDir, err := hostMountPoint(ctx, cli, id, dataDir) switch { case docker.IsErrConnectionFailed(err): - fmt.Fprintf(os.Stderr, "\n Docker socket must be mounted for the automatic upgrade of the internal database to proceed.\n") - fmt.Fprintf(os.Stderr, " 👉 docker run ... -v /var/run/docker.sock:/var/run/docker.sock:ro ...\n\n") + fmt.Fprintln(os.Stderr, "\n Docker socket must be mounted for the automatic upgrade of the internal database to proceed.") + fmt.Fprintln(os.Stderr, " 👉 docker run ... -v /var/run/docker.sock:/var/run/docker.sock:ro ...\n") return errors.New("Docker socket volume mount is missing") case err != nil: return errors.Wrap(err, "failed to determine host mount point") diff --git a/internal/debugserver/expvar.go b/internal/debugserver/expvar.go index 4badece8d24d..8a1b8d411510 100644 --- a/internal/debugserver/expvar.go +++ b/internal/debugserver/expvar.go @@ -13,16 +13,16 @@ import ( // can be mounted on any ServeMux, not just http.DefaultServeMux. func expvarHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, "{\n") + fmt.Fprintln(w, "{") first := true expvar.Do(func(kv expvar.KeyValue) { if !first { - fmt.Fprintf(w, ",\n") + fmt.Fprintln(w, ",") } first = false fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) }) - fmt.Fprintf(w, "\n}\n") + fmt.Fprintln(w, "\n}") } func gcHandler(w http.ResponseWriter, r *http.Request) { From 0fcfdcbe17bc2e5ca5b5d2bfdfc245dc2ecafd53 Mon Sep 17 00:00:00 2001 From: Rijnard van Tonder Date: Thu, 12 Dec 2019 11:42:36 -0700 Subject: [PATCH 2/2] Revert to Fprint due to inconsistent lint check The `Fprintln("...\n")` triggers https://github.com/golang/go/issues/18085#issuecomment-350383031, so using `Fprint("...\n")` instead. I'm changing it for both `Fprintf` calls in this block, even though the one can be `Fprintln` and the other `Fprint`, so that it's consistent and we don't see a weird mix of `Fprintln` and `Fprintf` here. --- cmd/server/shared/postgres.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/server/shared/postgres.go b/cmd/server/shared/postgres.go index a45aa010e9d2..6618e84d31d6 100644 --- a/cmd/server/shared/postgres.go +++ b/cmd/server/shared/postgres.go @@ -137,8 +137,8 @@ func maybeUpgradePostgres(path, newVersion string) (err error) { hostDataDir, err := hostMountPoint(ctx, cli, id, dataDir) switch { case docker.IsErrConnectionFailed(err): - fmt.Fprintln(os.Stderr, "\n Docker socket must be mounted for the automatic upgrade of the internal database to proceed.") - fmt.Fprintln(os.Stderr, " 👉 docker run ... -v /var/run/docker.sock:/var/run/docker.sock:ro ...\n") + fmt.Fprint(os.Stderr, "\n Docker socket must be mounted for the automatic upgrade of the internal database to proceed.\n") + fmt.Fprint(os.Stderr, " 👉 docker run ... -v /var/run/docker.sock:/var/run/docker.sock:ro ...\n\n") return errors.New("Docker socket volume mount is missing") case err != nil: return errors.Wrap(err, "failed to determine host mount point")