Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Sep 17, 2022
1 parent 42c1282 commit 1615eda
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
8 changes: 6 additions & 2 deletions config/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ type (
}
}

// general options
ServerBind string `long:"bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
Server struct {
// general options
Bind string `long:"server.bind" env:"SERVER_BIND" description:"Server address" default:":8080"`
ReadTimeout time.Duration `long:"server.timeout.read" env:"SERVER_TIMEOUT_READ" description:"Server read timeout" default:"5s"`
WriteTimeout time.Duration `long:"server.timeout.write" env:"SERVER_TIMEOUT_WRITE" description:"Server write timeout" default:"10s"`
}
}
)

Expand Down
4 changes: 2 additions & 2 deletions janitor/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest/to"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down
6 changes: 3 additions & 3 deletions janitor/janitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"sync"
"time"

"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources" //nolint:staticcheck
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/to"
tparse "github.com/karrick/tparse/v2"
Expand Down Expand Up @@ -146,7 +146,7 @@ func (j *Janitor) initPrometheus() {
prometheus.MustRegister(j.Prometheus.MetricErrors)
}

func (j *Janitor) subscriptionList(ctx context.Context) []subscriptions.Subscription {
func (j *Janitor) subscriptionList(ctx context.Context) map[string]subscriptions.Subscription {
subscriptionList, err := j.Azure.Client.ListCachedSubscriptionsWithFilter(ctx, j.Azure.Subscription...)
if err != nil {
log.Panic(err.Error())
Expand Down
4 changes: 2 additions & 2 deletions janitor/janitor_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package janitor

import (
"io/ioutil"
"io"
"testing"
"time"

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

logger := log.New()
logger.Out = ioutil.Discard
logger.Out = io.Discard
contextLogger := logger.WithField("type", "testing")

j := buildJanitorObj()
Expand Down
4 changes: 2 additions & 2 deletions janitor/resourcegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package janitor
import (
"context"

"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest/to"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down
4 changes: 2 additions & 2 deletions janitor/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package janitor
import (
"context"

"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/resources/mgmt/resources" //nolint:staticcheck
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest/to"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down
4 changes: 2 additions & 2 deletions janitor/roleassignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions"
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization"
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" //nolint:staticcheck
"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2020-04-01-preview/authorization" //nolint:staticcheck
"github.com/Azure/go-autorest/autorest/to"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
Expand Down
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -57,7 +58,7 @@ func main() {
j.Init()
j.Run()

log.Infof("starting http server on %s", opts.ServerBind)
log.Infof("starting http server on %s", opts.Server.Bind)
startHttpServer()
}

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

// check if there is an parse error
if err != nil {
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp {
var flagsErr *flags.Error
if ok := errors.As(err, &flagsErr); ok && flagsErr.Type == flags.ErrHelp {
os.Exit(0)
} else {
fmt.Println()
Expand Down Expand Up @@ -184,21 +186,29 @@ func initAzureConnection() {

// start and handle prometheus handler
func startHttpServer() {
mux := http.NewServeMux()

// healthz
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
if _, err := fmt.Fprint(w, "Ok"); err != nil {
log.Error(err)
}
})

// readyz
http.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
if _, err := fmt.Fprint(w, "Ok"); err != nil {
log.Error(err)
}
})

http.Handle("/metrics", azuretracing.RegisterAzureMetricAutoClean(promhttp.Handler()))
mux.Handle("/metrics", azuretracing.RegisterAzureMetricAutoClean(promhttp.Handler()))

log.Fatal(http.ListenAndServe(opts.ServerBind, nil))
srv := &http.Server{
Addr: opts.Server.Bind,
Handler: mux,
ReadTimeout: opts.Server.ReadTimeout,
WriteTimeout: opts.Server.WriteTimeout,
}
log.Fatal(srv.ListenAndServe())
}

0 comments on commit 1615eda

Please sign in to comment.