Merge pull request #14767 from sashamelentyev/print

all: Change Printf and friends to Print if there is no formatting
dependabot/go_modules/go.uber.org/atomic-1.10.0
Benjamin Wang 2022-11-16 10:38:20 +08:00 committed by GitHub
commit 8438ddae3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 40 additions and 41 deletions

View File

@ -115,7 +115,7 @@ func main() {
log.Fatalf("failed to create a session: %s", err)
}
log.Printf("created etcd client and session")
log.Print("created etcd client and session")
locker := concurrency.NewLocker(session, "/lock")
locker.Lock()
@ -127,9 +127,9 @@ func main() {
log.Printf("please manually revoke the lease using 'etcdctl lease revoke %x' or wait for it to expire, then start executing client 2 and hit any key...", version)
reader := bufio.NewReader(os.Stdin)
_, _ = reader.ReadByte()
log.Printf("resuming client 1")
log.Print("resuming client 1")
} else {
log.Printf("this is client 2, continuing\n")
log.Print("this is client 2, continuing\n")
}
err = write("key0", fmt.Sprintf("value from client %x", mode), int64(version))

View File

@ -172,7 +172,7 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {
fmt.Printf("ETCD_NAME=%q\n", newMemberName)
fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ","))
fmt.Printf("ETCD_INITIAL_ADVERTISE_PEER_URLS=%q\n", memberPeerURLs)
fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n")
fmt.Print("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n")
}
}

View File

@ -241,7 +241,7 @@ func (p *fieldsPrinter) RoleGet(role string, r v3.AuthRoleGetResponse) {
func (p *fieldsPrinter) RoleDelete(role string, r v3.AuthRoleDeleteResponse) { p.hdr(r.Header) }
func (p *fieldsPrinter) RoleList(r v3.AuthRoleListResponse) {
p.hdr(r.Header)
fmt.Printf(`"Roles" :`)
fmt.Print(`"Roles" :`)
for _, r := range r.Roles {
fmt.Printf(" %q", r)
}

View File

@ -213,7 +213,7 @@ func (s *simplePrinter) RoleGet(role string, r v3.AuthRoleGetResponse) {
if v3.GetPrefixRangeEnd(sKey) == sRangeEnd && len(sKey) > 0 {
fmt.Printf(" (prefix %s)", sKey)
}
fmt.Printf("\n")
fmt.Print("\n")
}
for _, perm := range r.Perm {
@ -269,11 +269,11 @@ func (s *simplePrinter) UserAdd(name string, r v3.AuthUserAddResponse) {
func (s *simplePrinter) UserGet(name string, r v3.AuthUserGetResponse) {
fmt.Printf("User: %s\n", name)
fmt.Printf("Roles:")
fmt.Print("Roles:")
for _, role := range r.Roles {
fmt.Printf(" %s", role)
}
fmt.Printf("\n")
fmt.Print("\n")
}
func (s *simplePrinter) UserChangePassword(v3.AuthUserChangePasswordResponse) {

View File

@ -21,7 +21,7 @@ import (
"github.com/bgentry/speakeasy"
"github.com/spf13/cobra"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/cobrautl"
)
@ -199,7 +199,7 @@ func userGetCommandFunc(cmd *cobra.Command, args []string) {
if userShowDetail {
fmt.Printf("User: %s\n", name)
for _, role := range resp.Roles {
fmt.Printf("\n")
fmt.Print("\n")
roleResp, err := client.Auth.RoleGet(context.TODO(), role)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitError, err)

View File

@ -138,7 +138,7 @@ func copyFloats(s []float64) (c []float64) {
func (r *report) String() (s string) {
if len(r.stats.Lats) > 0 {
s += fmt.Sprintf("\nSummary:\n")
s += "\nSummary:\n"
s += fmt.Sprintf(" Total:\t%s.\n", r.sec2str(r.stats.Total.Seconds()))
s += fmt.Sprintf(" Slowest:\t%s.\n", r.sec2str(r.stats.Slowest))
s += fmt.Sprintf(" Fastest:\t%s.\n", r.sec2str(r.stats.Fastest))
@ -226,7 +226,7 @@ func percentiles(nums []float64) (data []float64) {
func (r *report) sprintLatencies() string {
data := percentiles(r.stats.Lats)
s := fmt.Sprintf("\nLatency distribution:\n")
s := "\nLatency distribution:\n"
for i := 0; i < len(pctls); i++ {
if data[i] > 0 {
s += fmt.Sprintf(" %v%% in %s.\n", pctls[i], r.sec2str(data[i]))
@ -257,7 +257,7 @@ func (r *report) histogram() string {
bi++
}
}
s := fmt.Sprintf("\nResponse time histogram:\n")
s := "\nResponse time histogram:\n"
for i := 0; i < len(buckets); i++ {
// Normalize bar lengths.
var barLen int
@ -270,7 +270,7 @@ func (r *report) histogram() string {
}
func (r *report) errors() string {
s := fmt.Sprintf("\nError distribution:\n")
s := "\nError distribution:\n"
for err, num := range r.stats.ErrorDist {
s += fmt.Sprintf(" [%d]\t%s\n", num, err)
}

View File

@ -246,7 +246,7 @@ func (pr *Progress) String() string {
fmt.Fprintf(&buf, " pendingSnap=%d", pr.PendingSnapshot)
}
if !pr.RecentActive {
fmt.Fprintf(&buf, " inactive")
fmt.Fprint(&buf, " inactive")
}
if n := pr.Inflights.Count(); n > 0 {
fmt.Fprintf(&buf, " inflight=%d", n)

View File

@ -87,7 +87,7 @@ func (c Config) String() string {
fmt.Fprintf(&buf, " learners_next=%s", quorum.MajorityConfig(c.LearnersNext).String())
}
if c.AutoLeave {
fmt.Fprintf(&buf, " autoleave")
fmt.Fprint(&buf, " autoleave")
}
return buf.String()
}

View File

@ -161,14 +161,14 @@ func DescribeMessage(m pb.Message, f EntryFormatter) string {
fmt.Fprintf(&buf, " Commit:%d", m.Commit)
}
if len(m.Entries) > 0 {
fmt.Fprintf(&buf, " Entries:[")
fmt.Fprint(&buf, " Entries:[")
for i, e := range m.Entries {
if i != 0 {
buf.WriteString(", ")
}
buf.WriteString(DescribeEntry(e, f))
}
fmt.Fprintf(&buf, "]")
fmt.Fprint(&buf, "]")
}
if s := m.Snapshot; s != nil && !IsEmptySnap(*s) {
fmt.Fprintf(&buf, " Snapshot: %s", DescribeSnapshot(*s))

View File

@ -34,14 +34,14 @@ func serveVars(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\n")
fmt.Fprint(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
fmt.Fprint(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
fmt.Fprint(w, "\n}\n")
}

View File

@ -17,7 +17,6 @@ package rafthttp
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
@ -127,7 +126,7 @@ func TestStreamReaderDialRequest(t *testing.T) {
}
req := act[0].Params[0].(*http.Request)
wurl := fmt.Sprintf("http://localhost:2380" + tt.endpoint(zaptest.NewLogger(t)) + "/1")
wurl := "http://localhost:2380" + tt.endpoint(zaptest.NewLogger(t)) + "/1"
if req.URL.String() != wurl {
t.Errorf("#%d: url = %s, want %s", i, req.URL.String(), wurl)
}

View File

@ -51,7 +51,7 @@ func TestEmpty(t *testing.T) {}
func TestMain(m *testing.M) {
// don't launch etcd server when invoked via go test
if strings.HasSuffix(os.Args[0], ".test") {
log.Printf("skip launching etcd server when invoked via go test")
log.Print("skip launching etcd server when invoked via go test")
return
}

View File

@ -24,7 +24,7 @@ import (
"github.com/stretchr/testify/require"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/pkg/v3/types"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework/e2e"
)
@ -127,7 +127,7 @@ func testCtlV3MoveLeader(t *testing.T, cfg e2e.EtcdProcessClusterConfig, envVars
},
{ // request to all endpoints
cx.epc.EndpointsV3(),
fmt.Sprintf("Leadership transferred"),
"Leadership transferred",
false,
},
}

View File

@ -45,12 +45,12 @@ func metricsTest(cx ctlCtx) {
for _, test := range []struct {
endpoint, expected string
}{
{"/metrics", fmt.Sprintf("etcd_mvcc_put_total 2")},
{"/metrics", fmt.Sprintf("etcd_debugging_mvcc_keys_total 1")},
{"/metrics", fmt.Sprintf("etcd_mvcc_delete_total 3")},
{"/metrics", "etcd_mvcc_put_total 2"},
{"/metrics", "etcd_debugging_mvcc_keys_total 1"},
{"/metrics", "etcd_mvcc_delete_total 3"},
{"/metrics", fmt.Sprintf(`etcd_server_version{server_version="%s"} 1`, version.Version)},
{"/metrics", fmt.Sprintf(`etcd_cluster_version{cluster_version="%s"} 1`, version.Cluster(version.Version))},
{"/metrics", fmt.Sprintf(`grpc_server_handled_total{grpc_code="Canceled",grpc_method="Watch",grpc_service="etcdserverpb.Watch",grpc_type="bidi_stream"} 6`)},
{"/metrics", `grpc_server_handled_total{grpc_code="Canceled",grpc_method="Watch",grpc_service="etcdserverpb.Watch",grpc_type="bidi_stream"} 6`},
{"/health", `{"health":"true","reason":""}`},
} {
i++

View File

@ -23,7 +23,7 @@ import (
"time"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/functional/rpcpb"
"go.uber.org/zap"
@ -445,7 +445,7 @@ func (ls *leaseStresser) attachKeysWithLease(leaseID int64) error {
for j := 0; j < ls.keysPerLease; j++ {
txnput := clientv3.OpPut(
fmt.Sprintf("%d%s%d", leaseID, "_", j),
fmt.Sprintf("bar"),
"bar",
clientv3.WithLease(clientv3.LeaseID(leaseID)),
)
txnPuts = append(txnPuts, txnput)

View File

@ -32,7 +32,7 @@ import (
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/embed"
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
"go.etcd.io/etcd/tests/v3/framework/testutils"
@ -90,7 +90,7 @@ func TestEmbedEtcd(t *testing.T) {
tests[7].cfg.LCUrls = []url.URL{*dnsURL}
tests[8].cfg.LPUrls = []url.URL{*dnsURL}
dir := filepath.Join(t.TempDir(), fmt.Sprintf("embed-etcd"))
dir := filepath.Join(t.TempDir(), "embed-etcd")
for i, tt := range tests {
tests[i].cfg.Dir = dir
@ -144,7 +144,7 @@ func testEmbedEtcdGracefulStop(t *testing.T, secure bool) {
urls := newEmbedURLs(secure, 2)
setupEmbedCfg(cfg, []url.URL{urls[0]}, []url.URL{urls[1]})
cfg.Dir = filepath.Join(t.TempDir(), fmt.Sprintf("embed-etcd"))
cfg.Dir = filepath.Join(t.TempDir(), "embed-etcd")
e, err := embed.StartEtcd(cfg)
if err != nil {

View File

@ -63,7 +63,7 @@ func mustFindLeaderEndpoints(c *clientv3.Client) {
}
}
fmt.Fprintf(os.Stderr, "failed to find a leader endpoint\n")
fmt.Fprint(os.Stderr, "failed to find a leader endpoint\n")
os.Exit(1)
}

View File

@ -98,7 +98,7 @@ and output a hex encoded line of binary for each input line`)
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s confstate=%s\n",
walsnap.Term, walsnap.Index, nodes, confStateJSON)
case snap.ErrNoSnapshot:
fmt.Printf("Snapshot:\nempty\n")
fmt.Print("Snapshot:\nempty\n")
default:
log.Fatalf("Failed loading snapshot: %v", err)
}
@ -131,7 +131,7 @@ and output a hex encoded line of binary for each input line`)
fmt.Printf("%4s\t%10s\ttype\tdata", "term", "index")
if *streamdecoder != "" {
fmt.Printf("\tdecoder_status\tdecoded_data")
fmt.Print("\tdecoder_status\tdecoded_data")
}
fmt.Println()
@ -255,10 +255,10 @@ func printUnknownNormal(entry raftpb.Entry) {
func printConfChange(entry raftpb.Entry) {
fmt.Printf("%4d\t%10d", entry.Term, entry.Index)
fmt.Printf("\tconf")
fmt.Print("\tconf")
var r raftpb.ConfChange
if err := r.Unmarshal(entry.Data); err != nil {
fmt.Printf("\t???")
fmt.Print("\t???")
} else {
fmt.Printf("\tmethod=%s id=%s", r.Type, types.ID(r.NodeID))
}
@ -270,7 +270,7 @@ func printRequest(entry raftpb.Entry) {
fmt.Printf("%4d\t%10d\tnorm", entry.Term, entry.Index)
switch r.Method {
case "":
fmt.Printf("\tnoop")
fmt.Print("\tnoop")
case "SYNC":
fmt.Printf("\tmethod=SYNC time=%q", time.Unix(0, r.Time).UTC())
case "QGET", "DELETE":