Skip to content

Commit 1615eda

Browse files
committed
fix lint
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 42c1282 commit 1615eda

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

config/opts.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ type (
6262
}
6363
}
6464

65-
// general options
66-
ServerBind string `long:"bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
65+
Server struct {
66+
// general options
67+
Bind string `long:"server.bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
68+
ReadTimeout time.Duration `long:"server.timeout.read" env:"SERVER_TIMEOUT_READ" description:"Server read timeout" default:"5s"`
69+
WriteTimeout time.Duration `long:"server.timeout.write" env:"SERVER_TIMEOUT_WRITE" description:"Server write timeout" default:"10s"`
70+
}
6771
}
6872
)
6973

janitor/deployments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"time"
66

7-
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
8-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
7+
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
8+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
99
"github.com/Azure/go-autorest/autorest/to"
1010
"github.com/prometheus/client_golang/prometheus"
1111
log "github.com/sirupsen/logrus"

janitor/janitor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources"
11-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
10+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources" //nolint:staticcheck
11+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
1212
"github.com/Azure/go-autorest/autorest"
1313
"github.com/Azure/go-autorest/autorest/to"
1414
tparse "github.com/karrick/tparse/v2"
@@ -146,7 +146,7 @@ func (j *Janitor) initPrometheus() {
146146
prometheus.MustRegister(j.Prometheus.MetricErrors)
147147
}
148148

149-
func (j *Janitor) subscriptionList(ctx context.Context) []subscriptions.Subscription {
149+
func (j *Janitor) subscriptionList(ctx context.Context) map[string]subscriptions.Subscription {
150150
subscriptionList, err := j.Azure.Client.ListCachedSubscriptionsWithFilter(ctx, j.Azure.Subscription...)
151151
if err != nil {
152152
log.Panic(err.Error())

janitor/janitor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package janitor
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"testing"
66
"time"
77

@@ -56,7 +56,7 @@ func TestResourceGroupExpiry(t *testing.T) {
5656
var resourceExpireTime *time.Time
5757

5858
logger := log.New()
59-
logger.Out = ioutil.Discard
59+
logger.Out = io.Discard
6060
contextLogger := logger.WithField("type", "testing")
6161

6262
j := buildJanitorObj()

janitor/resourcegroups.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package janitor
33
import (
44
"context"
55

6-
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
7-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
6+
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
7+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
88
"github.com/Azure/go-autorest/autorest/to"
99
"github.com/prometheus/client_golang/prometheus"
1010
log "github.com/sirupsen/logrus"

janitor/resources.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package janitor
33
import (
44
"context"
55

6-
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
7-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
6+
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
7+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
88
"github.com/Azure/go-autorest/autorest/to"
99
"github.com/prometheus/client_golang/prometheus"
1010
log "github.com/sirupsen/logrus"

janitor/roleassignments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"time"
66

7-
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
8-
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization"
7+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
8+
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization" //nolint:staticcheck
99
"github.com/Azure/go-autorest/autorest/to"
1010
"github.com/prometheus/client_golang/prometheus"
1111
log "github.com/sirupsen/logrus"

main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"net/http"
67
"os"
@@ -57,7 +58,7 @@ func main() {
5758
j.Init()
5859
j.Run()
5960

60-
log.Infof("starting http server on %s", opts.ServerBind)
61+
log.Infof("starting http server on %s", opts.Server.Bind)
6162
startHttpServer()
6263
}
6364

@@ -68,7 +69,8 @@ func initArgparser() {
6869

6970
// check if there is an parse error
7071
if err != nil {
71-
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
72+
var flagsErr *flags.Error
73+
if ok := errors.As(err, &flagsErr); ok && flagsErr.Type == flags.ErrHelp {
7274
os.Exit(0)
7375
} else {
7476
fmt.Println()
@@ -184,21 +186,29 @@ func initAzureConnection() {
184186

185187
// start and handle prometheus handler
186188
func startHttpServer() {
189+
mux := http.NewServeMux()
190+
187191
// healthz
188-
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
192+
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
189193
if _, err := fmt.Fprint(w, "Ok"); err != nil {
190194
log.Error(err)
191195
}
192196
})
193197

194198
// readyz
195-
http.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
199+
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
196200
if _, err := fmt.Fprint(w, "Ok"); err != nil {
197201
log.Error(err)
198202
}
199203
})
200204

201-
http.Handle("/metrics", azuretracing.RegisterAzureMetricAutoClean(promhttp.Handler()))
205+
mux.Handle("/metrics", azuretracing.RegisterAzureMetricAutoClean(promhttp.Handler()))
202206

203-
log.Fatal(http.ListenAndServe(opts.ServerBind, nil))
207+
srv := &http.Server{
208+
Addr: opts.Server.Bind,
209+
Handler: mux,
210+
ReadTimeout: opts.Server.ReadTimeout,
211+
WriteTimeout: opts.Server.WriteTimeout,
212+
}
213+
log.Fatal(srv.ListenAndServe())
204214
}

0 commit comments

Comments
 (0)