Skip to content

Commit

Permalink
Merge pull request #14494 from demoManito/remove/redundant-type-conve…
Browse files Browse the repository at this point in the history
…rsion

etcd: remove redundant type conversion
  • Loading branch information
serathius authored Sep 21, 2022
2 parents 6333f37 + a9c3d56 commit 0267944
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 28 deletions.
12 changes: 8 additions & 4 deletions client/pkg/srv/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
// GetCluster gets the cluster information via DNS discovery.
// Also sees each entry as a separate instance.
func GetCluster(serviceScheme, service, name, dns string, apurls types.URLs) ([]string, error) {
tempName := int(0)
tcp2ap := make(map[string]url.URL)

// First, resolve the apurls
Expand All @@ -45,7 +44,10 @@ func GetCluster(serviceScheme, service, name, dns string, apurls types.URLs) ([]
tcp2ap[tcpAddr.String()] = url
}

var stringParts []string
var (
tempName int
stringParts []string
)
updateNodeMap := func(service, scheme string) error {
_, addrs, err := lookupSRV(service, "tcp", dns)
if err != nil {
Expand Down Expand Up @@ -97,8 +99,10 @@ type SRVClients struct {

// GetClient looks up the client endpoints for a service and domain.
func GetClient(service, domain string, serviceName string) (*SRVClients, error) {
var urls []*url.URL
var srvs []*net.SRV
var (
urls []*url.URL
srvs []*net.SRV
)

updateURLs := func(service, scheme string) error {
_, addrs, err := lookupSRV(service, "tcp", domain)
Expand Down
2 changes: 1 addition & 1 deletion client/pkg/testutil/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type recorderStream struct {
}

func NewRecorderStream() Recorder {
return NewRecorderStreamWithWaitTimout(time.Duration(5 * time.Second))
return NewRecorderStreamWithWaitTimout(5 * time.Second)
}

func NewRecorderStreamWithWaitTimout(waitTimeout time.Duration) Recorder {
Expand Down
2 changes: 1 addition & 1 deletion client/v2/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (m *httpMembersAPI) List(ctx context.Context) ([]Member, error) {
return nil, err
}

return []Member(mCollection), nil
return mCollection, nil
}

func (m *httpMembersAPI) Add(ctx context.Context, peerURL string) (*Member, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cpuutil/endian.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
"unsafe"
)

const intWidth int = int(unsafe.Sizeof(0))
const intWidth = int(unsafe.Sizeof(0))

var byteOrder binary.ByteOrder

// ByteOrder returns the byte order for the CPU's native endianness.
func ByteOrder() binary.ByteOrder { return byteOrder }

func init() {
i := int(0x1)
i := 0x1
if v := (*[intWidth]byte)(unsafe.Pointer(&i)); v[0] == 0 {
byteOrder = binary.BigEndian
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/flags/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ func NewStringsValue(s string) (ss *StringsValue) {

// StringsFromFlag returns a string slice from the flag.
func StringsFromFlag(fs *flag.FlagSet, flagName string) []string {
return []string(*fs.Lookup(flagName).Value.(*StringsValue))
return *fs.Lookup(flagName).Value.(*StringsValue)
}
2 changes: 1 addition & 1 deletion pkg/flags/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ func NewURLsValue(s string) *URLsValue {

// URLsFromFlag returns a slices from url got from the flag.
func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL {
return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue))
return *fs.Lookup(urlsFlagName).Value.(*URLsValue)
}
6 changes: 3 additions & 3 deletions pkg/traceutil/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestLogIfLong(t *testing.T) {
}{
{
name: "When the duration is smaller than threshold",
threshold: time.Duration(200 * time.Millisecond),
threshold: 200 * time.Millisecond,
trace: &Trace{
operation: "Test",
startTime: time.Now().Add(-100 * time.Millisecond),
Expand All @@ -250,7 +250,7 @@ func TestLogIfLong(t *testing.T) {
},
{
name: "When the duration is longer than threshold",
threshold: time.Duration(50 * time.Millisecond),
threshold: 50 * time.Millisecond,
trace: &Trace{
operation: "Test",
startTime: time.Now().Add(-100 * time.Millisecond),
Expand All @@ -265,7 +265,7 @@ func TestLogIfLong(t *testing.T) {
},
{
name: "When not all steps are longer than step threshold",
threshold: time.Duration(50 * time.Millisecond),
threshold: 50 * time.Millisecond,
trace: &Trace{
operation: "Test",
startTime: time.Now().Add(-100 * time.Millisecond),
Expand Down
2 changes: 1 addition & 1 deletion raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var stmap = [...]string{
}

func (st StateType) String() string {
return stmap[uint64(st)]
return stmap[st]
}

// Config contains the parameters to start a raft.
Expand Down
2 changes: 1 addition & 1 deletion raft/tracker/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ var prstmap = [...]string{
"StateSnapshot",
}

func (st StateType) String() string { return prstmap[uint64(st)] }
func (st StateType) String() string { return prstmap[st] }
12 changes: 6 additions & 6 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"go.etcd.io/etcd/client/pkg/v3/tlsutil"
"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/pkg/v3/flags"
"go.etcd.io/etcd/pkg/v3/netutil"
"go.etcd.io/etcd/server/v3/config"
Expand Down Expand Up @@ -572,7 +572,7 @@ func (cfg *configYAML) configFromFile(path string) error {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-peer-urls: %v\n", err)
os.Exit(1)
}
cfg.LPUrls = []url.URL(u)
cfg.LPUrls = u
}

if cfg.LCUrlsJSON != "" {
Expand All @@ -581,7 +581,7 @@ func (cfg *configYAML) configFromFile(path string) error {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-client-urls: %v\n", err)
os.Exit(1)
}
cfg.LCUrls = []url.URL(u)
cfg.LCUrls = u
}

if cfg.APUrlsJSON != "" {
Expand All @@ -590,7 +590,7 @@ func (cfg *configYAML) configFromFile(path string) error {
fmt.Fprintf(os.Stderr, "unexpected error setting up initial-advertise-peer-urls: %v\n", err)
os.Exit(1)
}
cfg.APUrls = []url.URL(u)
cfg.APUrls = u
}

if cfg.ACUrlsJSON != "" {
Expand All @@ -599,7 +599,7 @@ func (cfg *configYAML) configFromFile(path string) error {
fmt.Fprintf(os.Stderr, "unexpected error setting up advertise-peer-urls: %v\n", err)
os.Exit(1)
}
cfg.ACUrls = []url.URL(u)
cfg.ACUrls = u
}

if cfg.ListenMetricsUrlsJSON != "" {
Expand All @@ -608,7 +608,7 @@ func (cfg *configYAML) configFromFile(path string) error {
fmt.Fprintf(os.Stderr, "unexpected error setting up listen-metrics-urls: %v\n", err)
os.Exit(1)
}
cfg.ListenMetricsUrls = []url.URL(u)
cfg.ListenMetricsUrls = u
}

if cfg.CORSJSON != "" {
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/etcdhttp/peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type fakeCluster struct {
func (c *fakeCluster) ID() types.ID { return types.ID(c.id) }
func (c *fakeCluster) ClientURLs() []string { return c.clientURLs }
func (c *fakeCluster) Members() []*membership.Member {
var ms membership.MembersByID
ms := make(membership.MembersByID, 0, len(c.members))
for _, m := range c.members {
ms = append(ms, m)
}
sort.Sort(ms)
return []*membership.Member(ms)
return ms
}
func (c *fakeCluster) Member(id types.ID) *membership.Member { return c.members[uint64(id)] }
func (c *fakeCluster) Version() *semver.Version { return nil }
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c *RaftCluster) Members() []*Member {
ms = append(ms, m.Clone())
}
sort.Sort(ms)
return []*Member(ms)
return ms
}

func (c *RaftCluster) Member(id types.ID) *Member {
Expand All @@ -149,7 +149,7 @@ func (c *RaftCluster) VotingMembers() []*Member {
}
}
sort.Sort(ms)
return []*Member(ms)
return ms
}

// MemberByName returns a Member with the given name if exists.
Expand Down
2 changes: 1 addition & 1 deletion server/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ func GetEffectiveNodeIDsFromWalEntries(lg *zap.Logger, snap *raftpb.Snapshot, en
sids = append(sids, id)
}
sort.Sort(sids)
return []uint64(sids)
return sids
}
4 changes: 2 additions & 2 deletions tests/e2e/v3_curl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func testV3CurlAuth(cx ctlCtx) {
}

// create root role
rolereq, err := json.Marshal(&pb.AuthRoleAddRequest{Name: string("root")})
rolereq, err := json.Marshal(&pb.AuthRoleAddRequest{Name: "root"})
testutil.AssertNil(cx.t, err)

if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/auth/role/add"), Value: string(rolereq), Expected: "revision"}); err != nil {
Expand All @@ -221,7 +221,7 @@ func testV3CurlAuth(cx ctlCtx) {
}

// enable auth
if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/auth/enable"), Value: string("{}"), Expected: "revision"}); err != nil {
if err = e2e.CURLPost(cx.epc, e2e.CURLReq{Endpoint: path.Join(p, "/auth/enable"), Value: "{}", Expected: "revision"}); err != nil {
cx.t.Fatalf("failed testV3CurlAuth enable auth with curl using prefix (%s) (%v)", p, err)
}

Expand Down

0 comments on commit 0267944

Please sign in to comment.