summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2025-05-06 12:40:47 +0200
committerJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2025-05-06 12:40:47 +0200
commit347b20fc91505584bc9efbeca89590a411b95e79 (patch)
tree9dfc600e957c4a881115f8bc8a9cc107a4f0cc9c
parent9c4985368aee638d982f30ea7bc5c7ee71ae3ab3 (diff)
All: Run modernize --test --fix
-rw-r--r--client/client.go2
-rw-r--r--client/client_test.go14
-rw-r--r--client/fsm.go2
-rw-r--r--client/id.go9
-rw-r--r--cmd/eduvpn-cli/main.go10
-rw-r--r--i18nerr/i18nerr.go10
-rw-r--r--internal/api/api.go2
-rw-r--r--internal/api/api_test.go15
-rw-r--r--internal/config/v2/convert.go5
-rw-r--r--internal/discovery/discovery.go2
-rw-r--r--internal/fsm/fsm.go8
-rw-r--r--internal/fsm/fsm_test.go8
-rw-r--r--internal/levenshtein/levenshtein.go4
-rw-r--r--internal/log/log.go12
-rw-r--r--internal/verify/verify_test.go2
-rw-r--r--internal/wireguard/ini/ini.go3
-rw-r--r--proxy/proxy.go2
-rw-r--r--types/server/server.go2
18 files changed, 54 insertions, 58 deletions
diff --git a/client/client.go b/client/client.go
index d3e438f..6c905ca 100644
--- a/client/client.go
+++ b/client/client.go
@@ -113,7 +113,7 @@ func (c *Client) goTransition(id fsm.StateID) error {
// - debug: whether or not we want to enable debugging
//
// It returns an error if initialization failed, for example when discovery cannot be obtained and when there are no servers.
-func New(name string, version string, directory string, stateCallback func(FSMStateID, FSMStateID, interface{}) bool, debug bool) (c *Client, err error) {
+func New(name string, version string, directory string, stateCallback func(FSMStateID, FSMStateID, any) bool, debug bool) (c *Client, err error) {
// We create the client by filling fields one by one
c = &Client{}
diff --git a/client/client_test.go b/client/client_test.go
index 281ce55..9f302c4 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -60,7 +60,7 @@ func stateCallback(
ck *cookie.Cookie,
_ FSMStateID,
newState FSMStateID,
- data interface{},
+ data any,
) {
if newState == StateOAuthStarted {
url, ok := data.(string)
@@ -82,7 +82,7 @@ func TestServer(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
dir,
- func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
+ func(oldState FSMStateID, newState FSMStateID, data any) bool {
// test if main server server list succeeds
if newState == StateMain {
_, listErr := state.ServerList()
@@ -137,7 +137,7 @@ func TestTokenExpired(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
dir,
- func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
+ func(oldState FSMStateID, newState FSMStateID, data any) bool {
go stateCallback(ck, oldState, newState, data)
return true
},
@@ -196,7 +196,7 @@ func TestInvalidProfileCorrected(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
dir,
- func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
+ func(oldState FSMStateID, newState FSMStateID, data any) bool {
go stateCallback(ck, oldState, newState, data)
return true
},
@@ -253,7 +253,7 @@ func TestConfigStartup(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
dir,
- func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
+ func(oldState FSMStateID, newState FSMStateID, data any) bool {
go stateCallback(ck, oldState, newState, data)
return true
},
@@ -314,7 +314,7 @@ func TestPreferTCP(t *testing.T) {
"org.letsconnect-vpn.app.linux",
"0.1.0-test",
dir,
- func(oldState FSMStateID, newState FSMStateID, data interface{}) bool {
+ func(oldState FSMStateID, newState FSMStateID, data any) bool {
go stateCallback(ck, oldState, newState, data)
return true
},
@@ -379,7 +379,7 @@ func TestInvalidClientID(t *testing.T) {
k,
"0.1.0-test",
dir,
- func(_ FSMStateID, _ FSMStateID, _ interface{}) bool {
+ func(_ FSMStateID, _ FSMStateID, _ any) bool {
return true
},
false,
diff --git a/client/fsm.go b/client/fsm.go
index 728d572..d22f947 100644
--- a/client/fsm.go
+++ b/client/fsm.go
@@ -90,7 +90,7 @@ func GetStateName(s FSMStateID) string {
}
func newFSM(
- callback func(FSMStateID, FSMStateID, interface{}) bool,
+ callback func(FSMStateID, FSMStateID, any) bool,
) fsm.FSM {
states := FSMStates{
StateDeregistered: FSMState{
diff --git a/client/id.go b/client/id.go
index b4e1670..165e2a0 100644
--- a/client/id.go
+++ b/client/id.go
@@ -1,5 +1,7 @@
package client
+import "slices"
+
// isAllowedClientID checks if the 'clientID' is in the list of allowed client IDs
func isAllowedClientID(clientID string) bool {
allowList := []string{
@@ -22,12 +24,7 @@ func isAllowedClientID(clientID string) bool {
"org.govvpn.app.macos",
"org.govvpn.app.linux",
}
- for _, x := range allowList {
- if x == clientID {
- return true
- }
- }
- return false
+ return slices.Contains(allowList, clientID)
}
func userAgentName(clientID string) string {
diff --git a/cmd/eduvpn-cli/main.go b/cmd/eduvpn-cli/main.go
index 2a990f2..2dd0c31 100644
--- a/cmd/eduvpn-cli/main.go
+++ b/cmd/eduvpn-cli/main.go
@@ -19,7 +19,7 @@ import (
)
// Open a browser with xdg-open.
-func openBrowser(data interface{}) {
+func openBrowser(data any) {
str, ok := data.(string)
if !ok {
return
@@ -33,7 +33,7 @@ func openBrowser(data interface{}) {
}()
}
-func getProfileInteractive(profiles *srvtypes.Profiles, data interface{}) (string, error) {
+func getProfileInteractive(profiles *srvtypes.Profiles, data any) (string, error) {
fmt.Printf("Multiple VPN profiles found. Please select a profile by entering e.g. 1")
ps := ""
var options []string
@@ -59,7 +59,7 @@ func getProfileInteractive(profiles *srvtypes.Profiles, data interface{}) (strin
return p, nil
}
-func sendProfile(profile string, data interface{}) {
+func sendProfile(profile string, data any) {
d, ok := data.(*srvtypes.RequiredAskTransition)
if !ok {
fmt.Fprintf(os.Stderr, "\ninvalid data type: %v\n", reflect.TypeOf(data))
@@ -89,7 +89,7 @@ func sendProfile(profile string, data interface{}) {
// If OAuth is started we open the browser with the Auth URL
// If we ask for a profile, we send the profile using command line input
// Note that this has an additional argument, the vpn state which was wrapped into this callback function below.
-func stateCallback(_ client.FSMStateID, newState client.FSMStateID, data interface{}, prof string, dir string) {
+func stateCallback(_ client.FSMStateID, newState client.FSMStateID, data any, prof string, dir string) {
if newState == client.StateOAuthStarted {
openBrowser(data)
}
@@ -150,7 +150,7 @@ func printConfig(url string, cc string, srvType srvtypes.Type, prof string, debu
"org.eduvpn.app.linux",
fmt.Sprintf("%s-cli", version.Version),
dir,
- func(oldState client.FSMStateID, newState client.FSMStateID, data interface{}) bool {
+ func(oldState client.FSMStateID, newState client.FSMStateID, data any) bool {
stateCallback(oldState, newState, data, prof, dir)
return true
},
diff --git a/i18nerr/i18nerr.go b/i18nerr/i18nerr.go
index 47518e7..438b135 100644
--- a/i18nerr/i18nerr.go
+++ b/i18nerr/i18nerr.go
@@ -45,7 +45,7 @@ func TranslatedInner(inner error) (string, bool) {
// The inner error always consists of the translation key and some formatting
type Error struct {
key message.Reference
- args []interface{}
+ args []any
wrapped *Error
Misc bool
}
@@ -121,7 +121,7 @@ func New(key message.Reference) *Error {
// Newf creates a new i18n error using a message reference and arguments.
// It formats this with fmt.Errorf
-func Newf(key message.Reference, args ...interface{}) *Error {
+func Newf(key message.Reference, args ...any) *Error {
_ = printerOrNew(language.English).Sprintf(key, args...)
return &Error{key: key, args: args}
}
@@ -136,7 +136,7 @@ func Wrap(err error, key message.Reference) *Error {
// Wrapf creates a new i18n error using an error to be wrapped 'err' and a prefix message reference 'key' with format arguments 'args'.
// It formats this with fmt.Errorf
-func Wrapf(err error, key message.Reference, args ...interface{}) *Error {
+func Wrapf(err error, key message.Reference, args ...any) *Error {
_ = printerOrNew(language.English).Sprintf(key, args...)
t, misc := TranslatedInner(err)
return &Error{key: key, args: args, wrapped: &Error{key: t, Misc: misc}, Misc: misc}
@@ -148,7 +148,7 @@ func NewInternal(disp string) *Error {
}
// NewInternalf creates an internal localised error from a display string and arguments
-func NewInternalf(disp string, args ...interface{}) *Error {
+func NewInternalf(disp string, args ...any) *Error {
return NewInternal(fmt.Sprintf(disp, args...))
}
@@ -158,7 +158,7 @@ func WrapInternal(err error, disp string) *Error {
}
// WrapInternalf wraps an error and a display string with args into a localised internal error
-func WrapInternalf(err error, disp string, args ...interface{}) *Error {
+func WrapInternalf(err error, disp string, args ...any) *Error {
return WrapInternal(err, fmt.Sprintf(disp, args...))
}
diff --git a/internal/api/api.go b/internal/api/api.go
index ea0fc6f..7111c45 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -378,7 +378,7 @@ func getEndpoints(ctx context.Context, url string, tp http.RoundTripper) (*endpo
type OAuthLogger struct{}
// Logf logs a message with parameters
-func (ol *OAuthLogger) Logf(msg string, params ...interface{}) {
+func (ol *OAuthLogger) Logf(msg string, params ...any) {
log.Logger.Debugf(msg, params...)
}
diff --git a/internal/api/api_test.go b/internal/api/api_test.go
index 2170743..f611f07 100644
--- a/internal/api/api_test.go
+++ b/internal/api/api_test.go
@@ -21,6 +21,7 @@ import (
"codeberg.org/eduVPN/eduvpn-common/types/protocol"
"codeberg.org/eduVPN/eduvpn-common/types/server"
"github.com/jwijenbergh/eduoauth-go"
+ "slices"
)
func tokenHandler(t *testing.T, gt []string) func(http.ResponseWriter, *http.Request) {
@@ -38,20 +39,18 @@ func tokenHandler(t *testing.T, gt []string) func(http.ResponseWriter, *http.Req
}
grant := parsed.Get("grant_type")
- for _, v := range gt {
- if v == grant {
- _, err = w.Write([]byte(`
+ if slices.Contains(gt, grant) {
+ _, err = w.Write([]byte(`
{
"access_token": "validaccess",
"refresh_token": "validrefresh",
"expires_in": 3600
}
`))
- if err != nil {
- t.Fatalf("failed writing in token handler: %v", err)
- }
- return
+ if err != nil {
+ t.Fatalf("failed writing in token handler: %v", err)
}
+ return
}
t.Fatalf("grant type: %v, not allowed", grant)
}
@@ -260,7 +259,7 @@ func TestAPIInfo(t *testing.T) {
cases := []struct {
hp test.HandlerPath
info *profiles.Info
- err interface{}
+ err any
}{
{
hp: test.HandlerPath{
diff --git a/internal/config/v2/convert.go b/internal/config/v2/convert.go
index 59b0d3e..f50ffaf 100644
--- a/internal/config/v2/convert.go
+++ b/internal/config/v2/convert.go
@@ -5,6 +5,7 @@ import (
"codeberg.org/eduVPN/eduvpn-common/internal/config/v1"
"codeberg.org/eduVPN/eduvpn-common/types/server"
+ "maps"
)
func v1AuthTime(st time.Time, ost time.Time) time.Time {
@@ -51,9 +52,7 @@ func FromV1(ver1 *v1.V1) *V2 {
lc = glc
}
- for k, v := range cust {
- res[k] = v
- }
+ maps.Copy(res, cust)
sec := gsrvs.SecureInternetHome
// if the home organization ID is filled we have secure internet present
if sec.HomeOrganizationID == "" {
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index c7eae95..3fcb68c 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -98,7 +98,7 @@ var DiscoURL = "https://disco.eduvpn.org/v2/"
// file is a helper function that gets a disco JSON and fills the structure with it
// If it was unsuccessful it returns an error.
-func (discovery *Discovery) file(ctx context.Context, jsonFile string, previousVersion uint64, last time.Time, structure interface{}) (time.Time, error) {
+func (discovery *Discovery) file(ctx context.Context, jsonFile string, previousVersion uint64, last time.Time, structure any) (time.Time, error) {
var newUpdate time.Time
// No HTTP client present, create one
if discovery.httpClient == nil {
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go
index 5985aa5..c3b9255 100644
--- a/internal/fsm/fsm.go
+++ b/internal/fsm/fsm.go
@@ -54,7 +54,7 @@ type FSM struct {
// StateCallback is the function ran when a transition occurs
// It takes the old state, the new state and the data and returns if this is handled by the client
- StateCallback func(StateID, StateID, interface{}) bool
+ StateCallback func(StateID, StateID, any) bool
// GetStateName gets the name of a state as a string
GetStateName func(StateID) string
@@ -64,7 +64,7 @@ type FSM struct {
}
// NewFSM creates a new finite state machine
-func NewFSM(current StateID, states States, callback func(StateID, StateID, interface{}) bool, nameGen func(StateID) string) FSM {
+func NewFSM(current StateID, states States, callback func(StateID, StateID, any) bool, nameGen func(StateID) string) FSM {
return FSM{
States: states,
Current: current,
@@ -97,7 +97,7 @@ func (fsm *FSM) CheckTransition(desired StateID) error {
// GoTransitionRequired transitions the state machine to a new state with associated state data 'data'
// If this transition is not handled by the client, it returns an error.
-func (fsm *FSM) GoTransitionRequired(newState StateID, data interface{}) error {
+func (fsm *FSM) GoTransitionRequired(newState StateID, data any) error {
oldState := fsm.Current
handled, err := fsm.GoTransitionWithData(newState, data)
@@ -114,7 +114,7 @@ func (fsm *FSM) GoTransitionRequired(newState StateID, data interface{}) error {
// GoTransitionWithData is a helper that transitions the state machine toward the 'newState' with associated state data 'data'
// It returns whether or not the transition is handled by the client.
-func (fsm *FSM) GoTransitionWithData(newState StateID, data interface{}) (bool, error) {
+func (fsm *FSM) GoTransitionWithData(newState StateID, data any) (bool, error) {
if err := fsm.CheckTransition(newState); err != nil {
return false, err
}
diff --git a/internal/fsm/fsm_test.go b/internal/fsm/fsm_test.go
index c160477..dc8ddc8 100644
--- a/internal/fsm/fsm_test.go
+++ b/internal/fsm/fsm_test.go
@@ -57,7 +57,7 @@ func testFSM() FSM {
Transitions: []Transition{},
},
}
- cb := func(StateID, StateID, interface{}) bool {
+ cb := func(StateID, StateID, any) bool {
return false
}
namecb := func(in StateID) string {
@@ -149,7 +149,7 @@ func TestGoTransitionRequired(t *testing.T) {
for _, c := range cases {
curr := machine.Current
- machine.StateCallback = func(_ StateID, newState StateID, data interface{}) bool {
+ machine.StateCallback = func(_ StateID, newState StateID, data any) bool {
if c.WantErr == "" && newState != c.In {
t.Fatalf("new state is not what we want, got: %v, want: %v", newState, c.In)
}
@@ -214,10 +214,10 @@ func TestGoTransition(t *testing.T) {
for _, c := range cases {
curr := machine.Current
- machine.StateCallback = func(StateID, StateID, interface{}) bool {
+ machine.StateCallback = func(StateID, StateID, any) bool {
return c.Handle
}
- machine.StateCallback = func(_ StateID, newState StateID, data interface{}) bool {
+ machine.StateCallback = func(_ StateID, newState StateID, data any) bool {
if c.WantErr == "" && newState != c.In {
t.Fatalf("new state is not what we want, got: %v, want: %v", newState, c.In)
}
diff --git a/internal/levenshtein/levenshtein.go b/internal/levenshtein/levenshtein.go
index 3be81c8..80f58a3 100644
--- a/internal/levenshtein/levenshtein.go
+++ b/internal/levenshtein/levenshtein.go
@@ -28,9 +28,9 @@ func levenshtein(os, ot string) int {
}
// loop through every word in the first string
- for i := 0; i < n; i++ {
+ for i := range n {
v1[0] = i + 1
- for j := 0; j < m; j++ {
+ for j := range m {
// calculate deletion cost,
// insertion cost and
// substitution cost to get from the string
diff --git a/internal/log/log.go b/internal/log/log.go
index b4abab3..e47a743 100644
--- a/internal/log/log.go
+++ b/internal/log/log.go
@@ -100,27 +100,27 @@ func (logger *FileLogger) Inherit(err error, msg string) {
}
// Debugf logs a message with parameters as level LevelDebug.
-func (logger *FileLogger) Debugf(msg string, params ...interface{}) {
+func (logger *FileLogger) Debugf(msg string, params ...any) {
logger.log(LevelDebug, msg, params...)
}
// Infof logs a message with parameters as level LevelInfo.
-func (logger *FileLogger) Infof(msg string, params ...interface{}) {
+func (logger *FileLogger) Infof(msg string, params ...any) {
logger.log(LevelInfo, msg, params...)
}
// Warningf logs a message with parameters as level LevelWarning.
-func (logger *FileLogger) Warningf(msg string, params ...interface{}) {
+func (logger *FileLogger) Warningf(msg string, params ...any) {
logger.log(LevelWarning, msg, params...)
}
// Errorf logs a message with parameters as level LevelError.
-func (logger *FileLogger) Errorf(msg string, params ...interface{}) {
+func (logger *FileLogger) Errorf(msg string, params ...any) {
logger.log(LevelError, msg, params...)
}
// Fatalf logs a message with parameters as level LevelFatal.
-func (logger *FileLogger) Fatalf(msg string, params ...interface{}) {
+func (logger *FileLogger) Fatalf(msg string, params ...any) {
logger.log(LevelFatal, msg, params...)
}
@@ -135,7 +135,7 @@ func (logger *FileLogger) filename(directory string) string {
}
// log logs as level 'level' a message 'msg' with parameters 'params'.
-func (logger *FileLogger) log(lvl Level, msg string, params ...interface{}) {
+func (logger *FileLogger) log(lvl Level, msg string, params ...any) {
if lvl >= logger.Level && logger.Level != LevelNotSet {
fMsg := fmt.Sprintf(msg, params...)
f := fmt.Sprintf("- Go - %s - %s", lvl.String(), fMsg)
diff --git a/internal/verify/verify_test.go b/internal/verify/verify_test.go
index aa373d1..0d91c42 100644
--- a/internal/verify/verify_test.go
+++ b/internal/verify/verify_test.go
@@ -20,7 +20,7 @@ func Test_verifyWithKeys(t *testing.T) {
// Get last line (key string) from file
scanner := bufio.NewScanner(file)
- for i := 0; i < 2; i++ {
+ for range 2 {
if !scanner.Scan() {
panic(scanner.Err())
}
diff --git a/internal/wireguard/ini/ini.go b/internal/wireguard/ini/ini.go
index 83fc614..842928a 100644
--- a/internal/wireguard/ini/ini.go
+++ b/internal/wireguard/ini/ini.go
@@ -7,6 +7,7 @@ package ini
import (
"errors"
"fmt"
+ "slices"
"strings"
)
@@ -65,7 +66,7 @@ func (ok *OrderedKeys) Remove(name string) {
if idx == -1 {
return
}
- *ok = append((*ok)[:idx], (*ok)[idx+1:]...)
+ *ok = slices.Delete((*ok), idx, idx+1)
}
// Section represents a single section within an ini file
diff --git a/proxy/proxy.go b/proxy/proxy.go
index a43083f..4c51aed 100644
--- a/proxy/proxy.go
+++ b/proxy/proxy.go
@@ -18,7 +18,7 @@ import (
type Logger struct{}
// Logf logs a message with parameters
-func (l *Logger) Logf(msg string, params ...interface{}) {
+func (l *Logger) Logf(msg string, params ...any) {
log.Logger.Infof("[Proxyguard] "+msg, params...)
}
diff --git a/types/server/server.go b/types/server/server.go
index 5d5d4ca..3b0d374 100644
--- a/types/server/server.go
+++ b/types/server/server.go
@@ -61,7 +61,7 @@ type RequiredAskTransition struct {
C *cookie.Cookie `json:"cookie,omitempty"`
// Data is the data associated to the transition, e.g. the list of profiles (Profiles struct)
// or the list of secure internet locations ([]string)
- Data interface{} `json:"data"`
+ Data any `json:"data"`
}
// Expiry is the struct that gives the time at which certain expiry elements should be shown