diff --git a/api/api.go b/api/api.go index 9528fe72..efc83a7c 100644 --- a/api/api.go +++ b/api/api.go @@ -1,4 +1,4 @@ -// Copyright 2015 clair authors +// Copyright 2017 clair authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import ( "github.com/coreos/clair/api/context" "github.com/coreos/clair/config" - "github.com/coreos/clair/utils" + "github.com/coreos/clair/pkg/stopper" "github.com/coreos/pkg/capnslog" ) @@ -35,7 +35,7 @@ const timeoutResponse = `{"Error":{"Message":"Clair failed to respond within the var log = capnslog.NewPackageLogger("github.com/coreos/clair", "api") -func Run(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) { +func Run(config *config.APIConfig, ctx *context.RouteContext, st *stopper.Stopper) { defer st.End() // Do not run the API service if there is no config. @@ -68,7 +68,7 @@ func Run(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) log.Info("main API stopped") } -func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *utils.Stopper) { +func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *stopper.Stopper) { defer st.End() // Do not run the API service if there is no config. @@ -94,8 +94,8 @@ func RunHealth(config *config.APIConfig, ctx *context.RouteContext, st *utils.St // listenAndServeWithStopper wraps graceful.Server's // ListenAndServe/ListenAndServeTLS and adds the ability to interrupt them with -// the provided utils.Stopper -func listenAndServeWithStopper(srv *graceful.Server, st *utils.Stopper, certFile, keyFile string) { +// the provided stopper.Stopper. +func listenAndServeWithStopper(srv *graceful.Server, st *stopper.Stopper, certFile, keyFile string) { go func() { <-st.Chan() srv.Stop(0) diff --git a/cmd/clair/main.go b/cmd/clair/main.go index 750c5fc6..3fa21556 100644 --- a/cmd/clair/main.go +++ b/cmd/clair/main.go @@ -32,8 +32,8 @@ import ( "github.com/coreos/clair/config" "github.com/coreos/clair/database" "github.com/coreos/clair/notifier" + "github.com/coreos/clair/pkg/stopper" "github.com/coreos/clair/updater" - "github.com/coreos/clair/utils" // Register database driver. _ "github.com/coreos/clair/database/pgsql" @@ -91,7 +91,7 @@ func stopCPUProfiling(f *os.File) { // Boot starts Clair instance with the provided config. func Boot(config *config.Config) { rand.Seed(time.Now().UnixNano()) - st := utils.NewStopper() + st := stopper.NewStopper() // Open database db, err := database.Open(config.Database) diff --git a/notifier/notifier.go b/notifier/notifier.go index ad3619fa..07ec8b7c 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -29,7 +29,7 @@ import ( "github.com/coreos/clair/database" "github.com/coreos/clair/ext/notification" "github.com/coreos/clair/pkg/commonerr" - "github.com/coreos/clair/utils" + "github.com/coreos/clair/pkg/stopper" ) const ( @@ -59,7 +59,7 @@ func init() { } // Run starts the Notifier service. -func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *utils.Stopper) { +func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *stopper.Stopper) { defer stopper.End() // Configure registered notifiers. @@ -122,7 +122,7 @@ func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *u log.Info("notifier service stopped") } -func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoAmI string, stopper *utils.Stopper) *database.VulnerabilityNotification { +func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoAmI string, stopper *stopper.Stopper) *database.VulnerabilityNotification { for { // Find a notification to send. notification, err := datastore.GetAvailableNotification(renotifyInterval) @@ -148,7 +148,7 @@ func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoA } } -func handleTask(n database.VulnerabilityNotification, st *utils.Stopper, maxAttempts int) (bool, bool) { +func handleTask(n database.VulnerabilityNotification, st *stopper.Stopper, maxAttempts int) (bool, bool) { // Send notification. for senderName, sender := range notification.Senders() { var attempts int diff --git a/utils/stopper.go b/pkg/stopper/stopper.go similarity index 97% rename from utils/stopper.go rename to pkg/stopper/stopper.go index e2ed6322..e939aa2a 100644 --- a/utils/stopper.go +++ b/pkg/stopper/stopper.go @@ -1,4 +1,4 @@ -// Copyright 2015 clair authors +// Copyright 2017 clair authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package utils +package stopper import ( "sync" diff --git a/updater/updater.go b/updater/updater.go index 0ae34970..267ea7fe 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -32,7 +32,7 @@ import ( "github.com/coreos/clair/database" "github.com/coreos/clair/ext/vulnmdsrc" "github.com/coreos/clair/ext/vulnsrc" - "github.com/coreos/clair/utils" + "github.com/coreos/clair/pkg/stopper" ) const ( @@ -70,7 +70,7 @@ func init() { } // Run updates the vulnerability database at regular intervals. -func Run(config *config.UpdaterConfig, datastore database.Datastore, st *utils.Stopper) { +func Run(config *config.UpdaterConfig, datastore database.Datastore, st *stopper.Stopper) { defer st.End() // Do not run the updater if there is no config or if the interval is 0.