From 685cbe1b4ab22743dbf7e0c1a3c95a11552ba933 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Thu, 18 Sep 2025 14:11:36 +0200 Subject: [PATCH 1/2] [+] bump `golangci/golangci-lint-action` to v8 --- .github/workflows/build.yml | 2 +- .golangci.yml | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2972bfd8..03a611ba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,7 +39,7 @@ jobs: - name: GolangCI-Lint if: runner.os == 'Linux' - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 with: version: latest args: --verbose diff --git a/.golangci.yml b/.golangci.yml index 11054b18..cb616f98 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,11 +1,27 @@ +version: "2" linters: enable: - gocyclo - - revive - misspell - - unused - -linters-settings: - gocyclo: - # minimal code complexity to report, 30 by default (but we recommend 10-20) - min-complexity: 16 \ No newline at end of file + - revive + settings: + gocyclo: + min-complexity: 16 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ From 2513c737bd21ffcffb54943a758aca5b71593c3a Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Thu, 18 Sep 2025 14:25:13 +0200 Subject: [PATCH 2/2] fix linter warnings --- checker/consul_leader_checker.go | 2 +- checker/patroni_leader_checker.go | 2 +- ipmanager/basicConfigurer.go | 6 +++--- ipmanager/hetznerConfigurer.go | 19 ++++++++++--------- vipconfig/config.go | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/checker/consul_leader_checker.go b/checker/consul_leader_checker.go index 9eefe5c7..1b8f8789 100644 --- a/checker/consul_leader_checker.go +++ b/checker/consul_leader_checker.go @@ -42,7 +42,7 @@ func NewConsulLeaderChecker(con *vipconfig.Config) (lc *ConsulLeaderChecker, err // GetChangeNotificationStream checks the status in the loop func (c *ConsulLeaderChecker) GetChangeNotificationStream(ctx context.Context, out chan<- bool) error { - kv := c.Client.KV() + kv := c.KV() queryOptions := &api.QueryOptions{ RequireConsistent: true, diff --git a/checker/patroni_leader_checker.go b/checker/patroni_leader_checker.go index f1c22193..2296a08a 100644 --- a/checker/patroni_leader_checker.go +++ b/checker/patroni_leader_checker.go @@ -47,7 +47,7 @@ func (c *PatroniLeaderChecker) GetChangeNotificationStream(ctx context.Context, case <-ctx.Done(): return nil case <-time.After(time.Duration(c.Interval) * time.Millisecond): - r, err := c.Client.Get(c.Endpoints[0] + c.TriggerKey) + r, err := c.Get(c.Endpoints[0] + c.TriggerKey) if err != nil { c.Logger.Sugar().Error("patroni REST API error:", err) continue diff --git a/ipmanager/basicConfigurer.go b/ipmanager/basicConfigurer.go index d5f1a255..2e65586b 100644 --- a/ipmanager/basicConfigurer.go +++ b/ipmanager/basicConfigurer.go @@ -23,7 +23,7 @@ type BasicConfigurer struct { func newBasicConfigurer(config *IPConfiguration) (*BasicConfigurer, error) { c := &BasicConfigurer{IPConfiguration: config, ntecontext: 0} if c.Iface.HardwareAddr == nil || c.Iface.HardwareAddr.String() == "00:00:00:00:00:00" { - return nil, errors.New(`Cannot run vip-manager on the loopback device + return nil, errors.New(`cannot run vip-manager on the loopback device as its hardware address is the local address (00:00:00:00:00:00), which prohibits sending of gratuitous ARP messages`) } @@ -70,9 +70,9 @@ func (c *BasicConfigurer) createGratuitousARP() ([]byte, error) { ProtAddressSize: IPv4AddressSize, Operation: layers.ARPReply, // Gratuitous ARP is sent as a reply SourceHwAddress: c.Iface.HardwareAddr, - SourceProtAddress: c.IPConfiguration.VIP.AsSlice(), + SourceProtAddress: c.VIP.AsSlice(), DstHwAddress: c.Iface.HardwareAddr, // Gratuitous ARP targets itself - DstProtAddress: c.IPConfiguration.VIP.AsSlice(), + DstProtAddress: c.VIP.AsSlice(), } // Create a packet with the layers diff --git a/ipmanager/hetznerConfigurer.go b/ipmanager/hetznerConfigurer.go index 1c00b994..152d4c56 100644 --- a/ipmanager/hetznerConfigurer.go +++ b/ipmanager/hetznerConfigurer.go @@ -84,7 +84,7 @@ func (c *HetznerConfigurer) curlQueryFailover(post bool) (string, error) { } if user == "" || password == "" { log.Infoln("Couldn't retrieve username or password from file", credentialsFile) - return "", errors.New("Couldn't retrieve username or password from file") + return "", errors.New("couldn't retrieve username or password from file") } /** @@ -101,33 +101,33 @@ func (c *HetznerConfigurer) curlQueryFailover(post bool) (string, error) { myOwnIP := getOutboundIP() if myOwnIP == nil { log.Error("Error determining this machine's IP address.") - return "", errors.New("Error determining this machine's IP address") + return "", errors.New("error determining this machine's IP address") } log.Infof("my_own_ip: %s\n", myOwnIP.String()) cmd = exec.Command("curl", "--ipv4", "-u", user+":"+password, - "https://robot-ws.your-server.de/failover/"+c.IPConfiguration.VIP.String(), + "https://robot-ws.your-server.de/failover/"+c.VIP.String(), "-d", "active_server_ip="+myOwnIP.String()) log.Debugf("%s %s %s '%s' %s %s %s", "curl", "--ipv4", "-u", user+":XXXXXX", - "https://robot-ws.your-server.de/failover/"+c.IPConfiguration.VIP.String(), + "https://robot-ws.your-server.de/failover/"+c.VIP.String(), "-d", "active_server_ip="+myOwnIP.String()) } else { cmd = exec.Command("curl", "--ipv4", "-u", user+":"+password, - "https://robot-ws.your-server.de/failover/"+c.IPConfiguration.VIP.String()) + "https://robot-ws.your-server.de/failover/"+c.VIP.String()) log.Debugf("%s %s %s %s %s", "curl", "--ipv4", "-u", user+":XXXXXX", - "https://robot-ws.your-server.de/failover/"+c.IPConfiguration.VIP.String()) + "https://robot-ws.your-server.de/failover/"+c.VIP.String()) } out, err := cmd.Output() @@ -164,7 +164,7 @@ func (c *HetznerConfigurer) getActiveIPFromJSON(str string) (net.IP, error) { errormap["status"].(float64), errormap["code"].(string), errormap["message"].(string)) - return nil, errors.New("Hetzner API returned error response") + return nil, errors.New("error response from Hetzner API returned") } if f["failover"] != nil { @@ -202,9 +202,10 @@ func (c *HetznerConfigurer) queryAddress() bool { /** no need to check, we can use "cached" state if set. * if it is set to UNKNOWN, a check will be done. */ - if c.cachedState == configured { + switch c.cachedState { + case configured: return true - } else if c.cachedState == released { + case released: return false } } diff --git a/vipconfig/config.go b/vipconfig/config.go index 1f20e9a8..bac19c6c 100644 --- a/vipconfig/config.go +++ b/vipconfig/config.go @@ -326,7 +326,7 @@ func NewConfig() (*Config, error) { // if a configfile has been passed, make viper read it if err = loadConfigFile(); err != nil { - return nil, fmt.Errorf("Fatal error reading config file: %w", err) + return nil, fmt.Errorf("fatal error reading config file: %w", err) } // convert string of csv to String Slice