Skip to content

Commit

Permalink
api: remove dependency on graceful
Browse files Browse the repository at this point in the history
This library has no longer been needed since Go 1.8.
  • Loading branch information
jzelinskie committed Sep 6, 2018
1 parent 2bbbad3 commit 30644fc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 131 deletions.
39 changes: 9 additions & 30 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
package api

import (
"context"
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net"
"net/http"
"time"

log "github.com/sirupsen/logrus"
"github.com/tylerb/graceful"

"github.com/coreos/clair/api/v3"
"github.com/coreos/clair/database"
Expand Down Expand Up @@ -61,42 +60,22 @@ func RunHealth(cfg *Config, store database.Datastore, st *stopper.Stopper) {
}
log.WithField("addr", cfg.HealthAddr).Info("starting health API")

srv := &graceful.Server{
Timeout: 10 * time.Second, // Interrupt health checks when stopping
NoSignalHandling: true, // We want to use our own Stopper
Server: &http.Server{
Addr: cfg.HealthAddr,
Handler: http.TimeoutHandler(newHealthHandler(store), cfg.Timeout, timeoutResponse),
},
srv := http.Server{
Addr: cfg.HealthAddr,
Handler: http.TimeoutHandler(newHealthHandler(store), cfg.Timeout, timeoutResponse),
}

listenAndServeWithStopper(srv, st, "", "")

log.Info("health API stopped")
}

// listenAndServeWithStopper wraps graceful.Server's
// ListenAndServe/ListenAndServeTLS and adds the ability to interrupt them with
// the provided stopper.Stopper.
func listenAndServeWithStopper(srv *graceful.Server, st *stopper.Stopper, certFile, keyFile string) {
go func() {
<-st.Chan()
srv.Stop(0)
srv.Shutdown(context.TODO())
}()

var err error
if certFile != "" && keyFile != "" {
log.Info("API: TLS Enabled")
err = srv.ListenAndServeTLS(certFile, keyFile)
} else {
err = srv.ListenAndServe()
err := srv.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
log.Fatal(err)
}

if err != nil {
if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
log.Fatal(err)
}
}
log.Info("health API stopped")
}

// tlsClientConfig initializes a *tls.Config using the given CA. The resulting
Expand Down
127 changes: 36 additions & 91 deletions bill-of-materials.json
Original file line number Diff line number Diff line change
@@ -1,132 +1,77 @@
[
{
"project": "github.com/beorn7/perks/quantile",
"licenses": [
{
"type": "MIT License",
"confidence": 0.9891304347826086
}
]
"project": "github.com/coreos/clair",
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/coreos/clair",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"project": "github.com/beorn7/perks/quantile",
"license": "MIT License",
"confidence": 0.989
},
{
"project": "github.com/coreos/pkg/timeutil",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/golang/protobuf/proto",
"licenses": [
{
"type": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.92
}
]
"license": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.92
},
{
"project": "github.com/google/uuid",
"license": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.966
},
{
"project": "github.com/matttproud/golang_protobuf_extensions/pbutil",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/pborman/uuid",
"licenses": [
{
"type": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.9663865546218487
}
]
"license": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.966
},
{
"project": "github.com/prometheus/client_golang/prometheus",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/prometheus/client_model/go",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/prometheus/common",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/prometheus/procfs",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
"project": "github.com/prometheus/procfs/xfs",
"license": "Apache License 2.0",
"confidence": 1
},
{
"project": "github.com/sirupsen/logrus",
"licenses": [
{
"type": "MIT License",
"confidence": 1
}
]
"license": "MIT License",
"confidence": 1
},
{
"project": "github.com/stretchr/testify/assert",
"licenses": [
{
"type": "MIT License",
"confidence": 0.9430051813471503
},
{
"type": "MIT License",
"confidence": 0.9430051813471503
}
]
"license": "MIT License",
"confidence": 0.943
},
{
"project": "github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew",
"licenses": [
{
"type": "ISC License",
"confidence": 0.9850746268656716
}
]
"license": "ISC License",
"confidence": 0.985
},
{
"project": "github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib",
"licenses": [
{
"type": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.9830508474576272
}
]
"license": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.983
}
]
18 changes: 10 additions & 8 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ import:
version: ^1.1.4
subpackages:
- assert
- package: github.com/tylerb/graceful
version: ^1.2.15
- package: gopkg.in/yaml.v2
- package: github.com/cockroachdb/cmux

0 comments on commit 30644fc

Please sign in to comment.