diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/api.go | 2 | ||||
| -rw-r--r-- | internal/api/api_test.go | 15 | ||||
| -rw-r--r-- | internal/config/v2/convert.go | 5 | ||||
| -rw-r--r-- | internal/discovery/discovery.go | 2 | ||||
| -rw-r--r-- | internal/fsm/fsm.go | 8 | ||||
| -rw-r--r-- | internal/fsm/fsm_test.go | 8 | ||||
| -rw-r--r-- | internal/levenshtein/levenshtein.go | 4 | ||||
| -rw-r--r-- | internal/log/log.go | 12 | ||||
| -rw-r--r-- | internal/verify/verify_test.go | 2 | ||||
| -rw-r--r-- | internal/wireguard/ini/ini.go | 3 |
10 files changed, 30 insertions, 31 deletions
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 |
