diff --git a/cli/cloud/cloudcmd/validators.go b/cli/cloud/cloudcmd/validators.go index 38d6f06e6..092d39668 100644 --- a/cli/cloud/cloudcmd/validators.go +++ b/cli/cloud/cloudcmd/validators.go @@ -155,6 +155,6 @@ func (v *Validators) checkPCRs(pcrs map[uint32][]byte) error { return nil } -func writeFmt(sb *strings.Builder, fmtStr string, args ...interface{}) { +func writeFmt(sb *strings.Builder, fmtStr string, args ...any) { sb.WriteString(fmt.Sprintf(fmtStr, args...)) } diff --git a/cli/file/file.go b/cli/file/file.go index d9abbd3c7..5e25ed59f 100644 --- a/cli/file/file.go +++ b/cli/file/file.go @@ -76,7 +76,7 @@ func (h *Handler) Write(name string, data []byte, options Option) error { // ReadJSON reads a JSON file from name and unmarshals it into the content interface. // The interface content must be a pointer to a JSON marchalable object. -func (h *Handler) ReadJSON(name string, content interface{}) error { +func (h *Handler) ReadJSON(name string, content any) error { data, err := h.Read(name) if err != nil { return err @@ -85,7 +85,7 @@ func (h *Handler) ReadJSON(name string, content interface{}) error { } // WriteJSON marshals the content interface to JSON and writes it to the path with the given name. -func (h *Handler) WriteJSON(name string, content interface{}, options Option) error { +func (h *Handler) WriteJSON(name string, content any, options Option) error { jsonData, err := json.MarshalIndent(content, "", "\t") if err != nil { return err diff --git a/cli/file/file_test.go b/cli/file/file_test.go index bac3ddb02..8fa520ada 100644 --- a/cli/file/file_test.go +++ b/cli/file/file_test.go @@ -25,7 +25,7 @@ func TestReadJSON(t *testing.T) { fs afero.Fs setupFs func(fs *afero.Afero) error name string - wantContent interface{} + wantContent any wantErr bool }{ "successful read": { @@ -83,7 +83,7 @@ func TestWriteJSON(t *testing.T) { fs afero.Fs setupFs func(af afero.Afero) error name string - content interface{} + content any options Option wantErr bool }{ diff --git a/cli/status/status_test.go b/cli/status/status_test.go index 32f5458b0..30e68019b 100644 --- a/cli/status/status_test.go +++ b/cli/status/status_test.go @@ -142,7 +142,7 @@ func stubNewConnFunc(errStub error) func(ctx context.Context, target string, opt type stubClientConn struct{} -func (c *stubClientConn) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error { +func (c *stubClientConn) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error { return nil } diff --git a/coordinator/atls/atls.go b/coordinator/atls/atls.go index f779d5cf2..3734866c5 100644 --- a/coordinator/atls/atls.go +++ b/coordinator/atls/atls.go @@ -148,7 +148,7 @@ type Validator interface { Validate(attDoc []byte, nonce []byte) ([]byte, error) } -func hashPublicKey(pub interface{}) ([]byte, error) { +func hashPublicKey(pub any) ([]byte, error) { pubBytes, err := x509.MarshalPKIXPublicKey(pub) if err != nil { return nil, err diff --git a/coordinator/attestation/gcp/validator_test.go b/coordinator/attestation/gcp/validator_test.go index 47f338336..ddcce3e5a 100644 --- a/coordinator/attestation/gcp/validator_test.go +++ b/coordinator/attestation/gcp/validator_test.go @@ -156,7 +156,7 @@ Y+t5OxL3kL15VzY1Ob0d5cMCAwEAAQ== } } -func mustMarshal(in interface{}, require *require.Assertions) []byte { +func mustMarshal(in any, require *require.Assertions) []byte { out, err := json.Marshal(in) require.NoError(err) return out diff --git a/coordinator/kubernetes/k8sapi/resources/marshal.go b/coordinator/kubernetes/k8sapi/resources/marshal.go index 8c0263204..6cda013d5 100644 --- a/coordinator/kubernetes/k8sapi/resources/marshal.go +++ b/coordinator/kubernetes/k8sapi/resources/marshal.go @@ -20,7 +20,7 @@ type Marshaler interface { } // MarshalK8SResources marshals every field of a struct into a k8s resource YAML. -func MarshalK8SResources(resources interface{}) ([]byte, error) { +func MarshalK8SResources(resources any) ([]byte, error) { if resources == nil { return nil, errors.New("marshal on nil called") } @@ -37,7 +37,7 @@ func MarshalK8SResources(resources interface{}) ([]byte, error) { // iterate over all struct fields for i := 0; i < elem.NumField(); i++ { field := elem.Field(i) - var inter interface{} + var inter any // check if value can be converted to interface if field.CanInterface() { inter = field.Addr().Interface() @@ -65,7 +65,7 @@ func MarshalK8SResources(resources interface{}) ([]byte, error) { } // UnmarshalK8SResources takes YAML and converts it into a k8s resources struct. -func UnmarshalK8SResources(data []byte, into interface{}) error { +func UnmarshalK8SResources(data []byte, into any) error { if into == nil { return errors.New("unmarshal on nil called") } @@ -86,7 +86,7 @@ func UnmarshalK8SResources(data []byte, into interface{}) error { for i := 0; i < value.NumField(); i++ { field := value.Field(i) - var inter interface{} + var inter any // check if value can be converted to interface if !field.CanInterface() { return fmt.Errorf("cannot use struct field %v as interface", i) @@ -131,7 +131,7 @@ func splitYAML(resources []byte) ([][]byte, error) { dec := yaml.NewDecoder(bytes.NewReader(resources)) var res [][]byte for { - var value interface{} + var value any err := dec.Decode(&value) if errors.Is(err, io.EOF) { break diff --git a/coordinator/kubernetes/k8sapi/resources/marshal_test.go b/coordinator/kubernetes/k8sapi/resources/marshal_test.go index 80d2ba1d1..885937895 100644 --- a/coordinator/kubernetes/k8sapi/resources/marshal_test.go +++ b/coordinator/kubernetes/k8sapi/resources/marshal_test.go @@ -13,7 +13,7 @@ import ( func TestMarshalK8SResources(t *testing.T) { testCases := map[string]struct { - resources interface{} + resources any wantErr bool wantYAML string }{ @@ -119,8 +119,8 @@ metadata: func TestUnmarshalK8SResources(t *testing.T) { testCases := map[string]struct { data string - into interface{} - wantObj interface{} + into any + wantObj any wantErr bool }{ "ConfigMap as only field can be unmarshaled": { diff --git a/coordinator/pubapi/coord.go b/coordinator/pubapi/coord.go index 78aa371de..2160b9cf3 100644 --- a/coordinator/pubapi/coord.go +++ b/coordinator/pubapi/coord.go @@ -393,7 +393,7 @@ func (a *API) assemblePeerStruct(vpnIP string, _ role.Role) (peer.Peer, error) { } func (a *API) newLogToCLIFunc(send func(string) error) logFunc { - return func(format string, v ...interface{}) { + return func(format string, v ...any) { if err := send(fmt.Sprintf(format, v...)); err != nil { a.logger.Error("logging to CLI failed", zap.Error(err)) } @@ -460,4 +460,4 @@ func (a *API) triggerNodeUpdate(nodePublicIP string) error { return err } -type logFunc func(format string, v ...interface{}) +type logFunc func(format string, v ...any) diff --git a/kms/kms/aws/aws_test.go b/kms/kms/aws/aws_test.go index bac103f43..b7ebe8058 100644 --- a/kms/kms/aws/aws_test.go +++ b/kms/kms/aws/aws_test.go @@ -140,7 +140,7 @@ func (m *fakeAWSClient) GetParametersForImport(ctx context.Context, params *kms. if err != nil { return nil, errors.New("Error generating Key Pair") } - var pki interface{} = &m.keyPairStruct.PublicKey + var pki any = &m.keyPairStruct.PublicKey publicKeyBytes, err := x509.MarshalPKIXPublicKey(pki) if err != nil { return nil, err