diff --git a/ctrd/image_proxy_util.go b/ctrd/image_proxy_util.go index e3ab9bfdf..f5f0accbb 100644 --- a/ctrd/image_proxy_util.go +++ b/ctrd/image_proxy_util.go @@ -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"}, } ) diff --git a/daemon/daemon.go b/daemon/daemon.go index f86111cf1..a758d1023 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -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 @@ -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 diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 3363c3880..3a63be7a3 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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" } diff --git a/test/util_api.go b/test/util_api.go index 687815290..99a2237d6 100644 --- a/test/util_api.go +++ b/test/util_api.go @@ -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) } }