Skip to content

Commit de3d21d

Browse files
committed
Fixup golangci-lint errors.
Signed-off-by: SuperQ <[email protected]>
1 parent 244a305 commit de3d21d

11 files changed

+26
-34
lines changed

.gitignore

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
.*.sw?
1+
# Build
2+
/.build
3+
/.release
4+
/.tarballs
25

3-
# IDEs
4-
.idea
5-
6-
# artifacts
7-
target
6+
# Artifacts
87
fortigate_exporter
8+
*.exe
99

1010
# coverage
1111
cover.out

.golangci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
linters:
3+
enable:
4+
- misspell
5+
- sloglint
6+
7+
issues:
8+
exclude-rules:
9+
- path: _test.go
10+
linters:
11+
- errcheck

internal/config/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ package config
1515

1616
import (
1717
"flag"
18-
"io/ioutil"
1918
"log"
19+
"os"
2020
"strings"
2121

2222
"gopkg.in/yaml.v2"
@@ -106,7 +106,7 @@ func ReInit() error {
106106
}
107107

108108
// parse AuthKeys
109-
af, err := ioutil.ReadFile(*parameter.AuthFile)
109+
af, err := os.ReadFile(*parameter.AuthFile)
110110
if err != nil {
111111
log.Fatalf("Failed to read API authentication map file: %v", err)
112112
return err
@@ -125,7 +125,7 @@ func ReInit() error {
125125
continue
126126
}
127127

128-
certs, err := ioutil.ReadFile(eca)
128+
certs, err := os.ReadFile(eca)
129129
if err != nil {
130130
log.Fatalf("Failed to read extra CA file %q: %v", eca, err)
131131
return err

pkg/http/forti_token_client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"context"
3535
"encoding/json"
3636
"fmt"
37-
"io/ioutil"
37+
"io"
3838
"net/http"
3939
"net/url"
4040

@@ -80,7 +80,7 @@ func (c *fortiTokenClient) Get(path string, query string, obj interface{}) error
8080
return fmt.Errorf("Response code was %d, expected 200 (path: %q)", resp.StatusCode, path)
8181
}
8282

83-
b, err := ioutil.ReadAll(resp.Body)
83+
b, err := io.ReadAll(resp.Body)
8484
if err != nil {
8585
return err
8686
}

pkg/http/forti_token_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ package http
3232

3333
import (
3434
"context"
35-
"io/ioutil"
35+
"io"
3636
"net/http"
3737
"net/url"
3838
"reflect"
@@ -47,7 +47,7 @@ type fakeHTTPClient struct {
4747

4848
func (c *fakeHTTPClient) Do(r *http.Request) (*http.Response, error) {
4949
return &http.Response{
50-
Body: ioutil.NopCloser(strings.NewReader(c.body)),
50+
Body: io.NopCloser(strings.NewReader(c.body)),
5151
StatusCode: c.status,
5252
}, nil
5353
}

pkg/probe/firewall_load_balance.go

-5
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,18 @@ func probeFirewallLoadBalance(c http.FortiHTTP, meta *TargetMetadata) ([]prometh
116116
switch realServer.Mode {
117117
case "active":
118118
realServerModeActive = 1.0
119-
break
120119
case "standby":
121120
realServerModeStandby = 1.0
122-
break
123121
case "disabled":
124122
realServerModeDisabled = 1.0
125-
break
126123
}
127124

128125
realServerStatusUp, realServerStatusDown, realServerStatusUnknown := 0.0, 0.0, 0.0
129126
switch realServer.Status {
130127
case "up":
131128
realServerStatusUp = 1.0
132-
break
133129
case "down":
134130
realServerStatusDown = 1.0
135-
break
136131
default:
137132
realServerStatusUnknown = 1.0
138133
}

pkg/probe/probe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (p *ProbeCollector) Probe(ctx context.Context, target map[string]string, hc
7878

7979
if target["token"] != "" && savedConfig.AuthKeys[config.Target(target["target"])].Token == "" {
8080
// Add the target and its apikey to the savedConfig and use, if exists, a target entry as a template for include/exclude
81-
// This will only happend the "first" time
81+
// This will only happened the "first" time
8282
savedConfig.AuthKeys[config.Target(target["target"])] = config.TargetAuth{Token: config.Token(target["token"]),
8383
Probes: savedConfig.AuthKeys[config.Target(target["profile"])].Probes}
8484
}

pkg/probe/probe_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
"log"
3636
"net/url"
3737

38-
"github.com/prometheus-community/fortigate_exporter/pkg/http"
3938
"github.com/google/go-jsonnet"
39+
"github.com/prometheus-community/fortigate_exporter/pkg/http"
4040
"github.com/prometheus/client_golang/prometheus"
4141
)
4242

pkg/probe/system_fortimanager.go

-7
Original file line numberDiff line numberDiff line change
@@ -58,35 +58,28 @@ func probeSystemFortimanagerStatus(c http.FortiHTTP, meta *TargetMetadata) ([]pr
5858
case 0:
5959
// No management Tunnel
6060
StatusDown = 1.0
61-
break
6261
case 1:
6362
// Management tunnel establishment in progress
6463
StatusHandshake = 1.0
65-
break
6664
case 2:
6765
// Management tunnel is establised
6866
StatusUp = 1.0
69-
break
7067
}
7168

7269
RegistrationUnknown, RegistrationInProgress, RegistrationRegistered, RegistrationUnregistered := 0.0, 0.0, 0.0, 0.0
7370
switch r.Results.Registration_ID {
7471
case 0:
7572
// FMG does not know about the device
7673
RegistrationUnknown = 1.0
77-
break
7874
case 1:
7975
// FMG does know the device, but it is not yet fully saved in the list of unregistered devices
8076
RegistrationInProgress = 1.0
81-
break
8277
case 2:
8378
// FMG does know the device, and device is authorized
8479
RegistrationRegistered = 1.0
85-
break
8680
case 3:
8781
// FMG does know the device, but it is not yet authorized
8882
RegistrationUnregistered = 1.0
89-
break
9083
}
9184

9285
m = append(m, prometheus.MustNewConstMetric(FortimanStat_id, prometheus.GaugeValue, StatusDown, r.VDOM, r.Results.Mode, "down"))

pkg/probe/system_link_monitor.go

-3
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@ func probeSystemLinkMonitor(c http.FortiHTTP, meta *TargetMetadata) ([]prometheu
117117
switch link.Status {
118118
case "up":
119119
wanStatusUp = 1.0
120-
break
121120
case "down":
122121
wanStatusDown = 1.0
123-
break
124122
case "error":
125123
wanStatusError = 1.0
126-
break
127124
default:
128125
wanStatusUnknown = 1.0
129126
}

pkg/probe/virtual_wan_health_check.go

-4
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,12 @@ func probeVirtualWANHealthCheck(c http.FortiHTTP, meta *TargetMetadata) ([]prome
117117
switch Member.Status {
118118
case "up":
119119
MemberStatusUp = 1.0
120-
break
121120
case "down":
122121
MemberStatusDown = 1.0
123-
break
124122
case "error":
125123
MemberStatusError = 1.0
126-
break
127124
case "disable":
128125
MemberStatusDisable = 1.0
129-
break
130126
default:
131127
MemberStatusUnknown = 1.0
132128
}

0 commit comments

Comments
 (0)