summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 15:04:47 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-11-28 15:04:47 +0100
commit3934d75ac516a530ceb9f494f7ce0de12cb1b5de (patch)
tree23c905ad43340e3192362afaeec8b6f6731575a8
parentf884b3df2762a1bd3799441e06659b9caad4ee6c (diff)
Lint: Use gocritic linter and fix errors returned by it
-rw-r--r--.github/workflows/test.yml2
-rw-r--r--cmd/cli/main.go13
-rw-r--r--internal/server/common.go11
-rw-r--r--internal/util/util.go2
-rw-r--r--types/server.go6
5 files changed, 17 insertions, 17 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 32e4fd9..2722385 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -16,7 +16,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
- args: -E stylecheck,revive
+ args: -E stylecheck,revive,gocritic
test-go:
name: Test Go
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index b1bcaa9..ab0b408 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -162,15 +162,14 @@ func main() {
customURLString := *customURLArg
urlString := *urlArg
secureInternetString := *secureInternet
- if customURLString != "" {
+ switch {
+ case customURLString != "":
printConfig(customURLString, ServerTypeCustom)
- return
- } else if urlString != "" {
+ case urlString != "":
printConfig(urlString, ServerTypeInstituteAccess)
- return
- } else if secureInternetString != "" {
+ case secureInternetString != "":
printConfig(secureInternetString, ServerTypeSecureInternet)
- return
+ default:
+ flag.PrintDefaults()
}
- flag.PrintDefaults()
}
diff --git a/internal/server/common.go b/internal/server/common.go
index 3db535c..f0274ed 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -508,16 +508,17 @@ func Config(server Server, clientSupportsWireguard bool, preferTCP bool) (string
var configType string
var configErr error
- // The config supports wireguard, do a specialized request with a public key
- if supportsWireguard {
+ switch {
+ // The config supports wireguard and optionally openvpn
+ case supportsWireguard:
// A wireguard connect call needs to generate a wireguard key and add it to the config
// Also the server could send back an OpenVPN config if it supports OpenVPN
config, configType, configErr = wireguardGetConfig(server, preferTCP, supportsOpenVPN)
- // The config only supports OpenVPN
- } else if supportsOpenVPN {
+ // The config only supports OpenVPN
+ case supportsOpenVPN:
config, configType, configErr = openVPNGetConfig(server, preferTCP)
// The config supports no available protocol because the profile only supports WireGuard but the client doesn't
- } else {
+ default:
return "", "", types.NewWrappedError(errorMessage, errors.New("no supported protocol found"))
}
diff --git a/internal/util/util.go b/internal/util/util.go
index 3ce1992..ddd165d 100644
--- a/internal/util/util.go
+++ b/internal/util/util.go
@@ -40,7 +40,7 @@ func EnsureValidURL(s string) (string, error) {
// Make sure the URL ends with a /
if returnedURL[len(returnedURL)-1:] != "/" {
- returnedURL = returnedURL + "/"
+ returnedURL += "/"
}
return returnedURL, nil
}
diff --git a/types/server.go b/types/server.go
index c15cb4e..5cd7353 100644
--- a/types/server.go
+++ b/types/server.go
@@ -34,13 +34,13 @@ type DiscoMapOrString map[string]string
// The display name can either be a map or a string in the server list
// Unmarshal it by first trying a string and then the map.
-func (DN *DiscoMapOrString) UnmarshalJSON(data []byte) error {
+func (displayName *DiscoMapOrString) UnmarshalJSON(data []byte) error {
var displayNameString string
err := json.Unmarshal(data, &displayNameString)
if err == nil {
- *DN = map[string]string{"en": displayNameString}
+ *displayName = map[string]string{"en": displayNameString}
return nil
}
@@ -49,7 +49,7 @@ func (DN *DiscoMapOrString) UnmarshalJSON(data []byte) error {
err = json.Unmarshal(data, &resultingMap)
if err == nil {
- *DN = resultingMap
+ *displayName = resultingMap
return nil
}
return err