Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gocyclo issues in go report #1084

Merged
merged 4 commits into from
Apr 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help to confirm this? Since I think it is introduced by your part. @Ace-Tang

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have communicated with @Ace-Tang offline. The change is totally reasonable.

}
)

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
1 change: 1 addition & 0 deletions test/util_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func PullImage(c *check.C, image string) {
q.Add("fromImage", image)
query := request.WithQuery(q)
resp, err = request.Post("/images/create", query)
c.Assert(err, check.IsNil)
c.Assert(resp.StatusCode, check.Equals, 200)
}
}