Skip to content

Commit

Permalink
Merge pull request #1084 from zhuangqh/fix-goreport
Browse files Browse the repository at this point in the history
fix: gocyclo issues in go report
  • Loading branch information
allencloud authored Apr 11, 2018
2 parents 15c9cbb + 20d2af5 commit a6fdc3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 48 deletions.
2 changes: 1 addition & 1 deletion ctrd/image_proxy_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func canonicalAddr(url *url.URL) string {
// change no_proxy to noProxy for avoid fail in go lint check
var (
noProxyEnv = &envOnce{
names: []string{"NO_PROXY", "noProxy"},
names: []string{"NO_PROXY", "no_proxy"},
}
)

Expand Down
18 changes: 13 additions & 5 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ func loadSymbolByName(p *plugin.Plugin, name string) (plugin.Symbol, error) {
return s, nil
}

// Run starts daemon.
func (d *Daemon) Run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

func (d *Daemon) loadPlugin() error {
var s plugin.Symbol
var err error

Expand Down Expand Up @@ -129,6 +125,18 @@ func (d *Daemon) Run() error {
}
}

return nil
}

// Run starts daemon.
func (d *Daemon) Run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if err := d.loadPlugin(); err != nil {
return err
}

imageMgr, err := internal.GenImageMgr(d.config, d)
if err != nil {
return err
Expand Down
56 changes: 14 additions & 42 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,21 @@ func FormatTimeInterval(input int64) (formattedTime string, err error) {
return "", errInvalid
}

if diff >= Year {
year := int(diff / Year)
formattedTime += strconv.Itoa(year) + " year"
if year > 1 {
formattedTime += "s"
}
} else if diff >= Month {
month := int(diff / Month)
formattedTime += strconv.Itoa(month) + " month"
if month > 1 {
formattedTime += "s"
}
} else if diff >= Week {
week := int(diff / Week)
formattedTime += strconv.Itoa(week) + " week"
if week > 1 {
formattedTime += "s"
}
} else if diff >= Day {
day := int(diff / Day)
formattedTime += strconv.Itoa(day) + " day"
if day > 1 {
formattedTime += "s"
}
} else if diff >= Hour {
hour := int(diff / Hour)
formattedTime += strconv.Itoa(hour) + " hour"
if hour > 1 {
formattedTime += "s"
}
} else if diff >= Minute {
minute := int(diff / Minute)
formattedTime += strconv.Itoa(minute) + " minute"
if minute > 1 {
formattedTime += "s"
}
} else if diff >= Second {
second := int(diff / Second)
formattedTime += strconv.Itoa(second) + " second"
if second > 1 {
formattedTime += "s"
timeThresholds := []time.Duration{Year, Month, Week, Day, Hour, Minute, Second}
timeNames := []string{"year", "month", "week", "day", "hour", "minute", "second"}

for i, threshold := range timeThresholds {
if diff >= threshold {
count := int(diff / threshold)
formattedTime += strconv.Itoa(count) + " " + timeNames[i]
if count > 1 {
formattedTime += "s"
}
break
}
} else {
}

if diff < Second {
formattedTime += "0 second"
}

Expand Down

0 comments on commit a6fdc3a

Please sign in to comment.