*: fix based on gosimple and unused

release-3.0
Gyu-Ho Lee 2016-04-07 22:09:25 -07:00
parent 9aec045fce
commit fb85da92e8
14 changed files with 20 additions and 49 deletions

View File

@ -45,16 +45,6 @@ func NewUniqueKV(ctx context.Context, kv v3.KV, pfx, val string, opts ...v3.OpOp
}
}
func waitUpdate(ctx context.Context, client *v3.Client, key string, opts ...v3.OpOption) error {
cctx, cancel := context.WithCancel(ctx)
defer cancel()
wresp, ok := <-client.Watch(cctx, key, opts...)
if !ok {
return ctx.Err()
}
return wresp.Err()
}
func waitDelete(ctx context.Context, client *v3.Client, key string, rev int64) error {
cctx, cancel := context.WithCancel(ctx)
defer cancel()

View File

@ -81,9 +81,11 @@ func restoreEtcd() error {
return runCommands(10, 2*time.Second)
}
var clusterHealthRegex = regexp.MustCompile(".*cluster is healthy.*")
var lineSplit = regexp.MustCompile("\n+")
var colonSplit = regexp.MustCompile("\\:")
var (
clusterHealthRegex = regexp.MustCompile(".*cluster is healthy.*")
lineSplit = regexp.MustCompile("\n+")
colonSplit = regexp.MustCompile(`\:`)
)
func runCommands(maxRetry int, interval time.Duration) error {
var retryCnt int

View File

@ -104,7 +104,7 @@ func handleClusterHealth(c *cli.Context) {
}
checked = true
if result.Health == "true" || nresult.Health == true {
if result.Health == "true" || nresult.Health {
health = true
fmt.Printf("member %s is healthy: got healthy result from %s\n", m.ID, url)
} else {

View File

@ -42,18 +42,6 @@ var (
defaultDialTimeout = 30 * time.Second
)
// trimsplit slices s into all substrings separated by sep and returns a
// slice of the substrings between the separator with all leading and trailing
// white space removed, as defined by Unicode.
func trimsplit(s, sep string) []string {
raw := strings.Split(s, ",")
trimmed := make([]string, 0)
for _, r := range raw {
trimmed = append(trimmed, strings.TrimSpace(r))
}
return trimmed
}
func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
if i < len(args) {
return args[i], nil

View File

@ -22,10 +22,7 @@ import (
"github.com/spf13/cobra"
)
var (
memberID uint64
memberPeerURLs string
)
var memberPeerURLs string
// NewMemberCommand returns the cobra command for "member".
func NewMemberCommand() *cobra.Command {

View File

@ -416,7 +416,7 @@ func TestCreateAndUpdateUser(t *testing.T) {
s := store{server: d, timeout: testTimeout, ensuredOnce: true, PasswordStore: fastPasswordStore{}}
out, created, err := s.CreateOrUpdateUser(user)
if created == false {
if !created {
t.Error("Should have created user, instead updated?")
}
if err != nil {
@ -427,7 +427,7 @@ func TestCreateAndUpdateUser(t *testing.T) {
t.Error("UpdateUser doesn't match given update. Got", out, "expected", expected)
}
out, created, err = s.CreateOrUpdateUser(update)
if created == true {
if created {
t.Error("Should have updated user, instead created?")
}
if err != nil {
@ -572,6 +572,7 @@ func TestEnableAuth(t *testing.T) {
t.Error("Unexpected error", err)
}
}
func TestDisableAuth(t *testing.T) {
trueval := "true"
falseval := "false"

View File

@ -144,9 +144,7 @@ func (c *RaftCluster) PeerURLs() []string {
defer c.Unlock()
urls := make([]string, 0)
for _, p := range c.members {
for _, addr := range p.PeerURLs {
urls = append(urls, addr)
}
urls = append(urls, p.PeerURLs...)
}
sort.Strings(urls)
return urls
@ -159,9 +157,7 @@ func (c *RaftCluster) ClientURLs() []string {
defer c.Unlock()
urls := make([]string, 0)
for _, p := range c.members {
for _, url := range p.ClientURLs {
urls = append(urls, url)
}
urls = append(urls, p.ClientURLs...)
}
sort.Strings(urls)
return urls

View File

@ -85,7 +85,7 @@ func (q *statsQueue) Rate() (float64, float64) {
return 0, 0
}
if time.Now().Sub(back.SendingTime) > time.Second {
if time.Since(back.SendingTime) > time.Second {
q.Clear()
return 0, 0
}

View File

@ -57,7 +57,7 @@ func (ss *ServerStats) JSON() []byte {
ss.Lock()
stats := *ss
ss.Unlock()
stats.LeaderInfo.Uptime = time.Now().Sub(stats.LeaderInfo.StartTime).String()
stats.LeaderInfo.Uptime = time.Since(stats.LeaderInfo.StartTime).String()
stats.SendingPkgRate, stats.SendingBandwidthRate = stats.SendRates()
stats.RecvingPkgRate, stats.RecvingBandwidthRate = stats.RecvRates()
b, err := json.Marshal(stats)

View File

@ -48,7 +48,7 @@ func CheckLeakedGoroutine() bool {
}
stackCount := make(map[string]int)
re := regexp.MustCompile("\\(0[0-9a-fx, ]*\\)")
re := regexp.MustCompile(`\(0[0-9a-fx, ]*\)`)
for _, g := range gs {
// strip out pointer arguments in first function of stack dump
normalized := string(re.ReplaceAll([]byte(g), []byte("(...)")))

View File

@ -289,7 +289,7 @@ func (s *store) Compact(rev int64) (<-chan struct{}, error) {
s.fifoSched.Schedule(j)
indexCompactionPauseDurations.Observe(float64(time.Now().Sub(start) / time.Millisecond))
indexCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond))
return ch, nil
}

View File

@ -21,7 +21,7 @@ import (
func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) bool {
totalStart := time.Now()
defer dbCompactionTotalDurations.Observe(float64(time.Now().Sub(totalStart) / time.Millisecond))
defer dbCompactionTotalDurations.Observe(float64(time.Since(totalStart) / time.Millisecond))
end := make([]byte, 8)
binary.BigEndian.PutUint64(end, uint64(compactMainRev+1))
@ -54,7 +54,7 @@ func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struc
// update last
revToBytes(revision{main: rev.main, sub: rev.sub + 1}, last)
tx.Unlock()
dbCompactionPauseDurations.Observe(float64(time.Now().Sub(start) / time.Millisecond))
dbCompactionPauseDurations.Observe(float64(time.Since(start) / time.Millisecond))
select {
case <-time.After(100 * time.Millisecond):

View File

@ -117,10 +117,7 @@ func (eh *EventHistory) clone() *EventHistory {
Back: eh.Queue.Back,
}
for i, e := range eh.Queue.Events {
clonedQueue.Events[i] = e
}
copy(clonedQueue.Events, eh.Queue.Events)
return &EventHistory{
StartIndex: eh.StartIndex,
Queue: clonedQueue,

View File

@ -345,7 +345,7 @@ func (s *store) Delete(nodePath string, dir, recursive bool) (*Event, error) {
}
// recursive implies dir
if recursive == true {
if recursive {
dir = true
}