From a83befa0d111a0ba6fac52d763e93c76a2ef94d4 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 19 Dec 2025 12:52:30 +0100 Subject: all: use any instead of interface{} Any is the preferred over interface{} now in Go. --- pkg/config/config.go | 6 +++--- pkg/config/merge.go | 10 +++++----- pkg/config/merge_test.go | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'pkg/config') diff --git a/pkg/config/config.go b/pkg/config/config.go index 5af99ba0f..0a0346f83 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -13,7 +13,7 @@ import ( "github.com/google/syzkaller/pkg/osutil" ) -func LoadFile(filename string, cfg interface{}) error { +func LoadFile(filename string, cfg any) error { if filename == "" { return fmt.Errorf("no config file specified") } @@ -24,7 +24,7 @@ func LoadFile(filename string, cfg interface{}) error { return LoadData(data, cfg) } -func LoadData(data []byte, cfg interface{}) error { +func LoadData(data []byte, cfg any) error { // Remove comment lines starting with #. data = regexp.MustCompile(`(^|\n)\s*#[^\n]*`).ReplaceAll(data, nil) dec := json.NewDecoder(bytes.NewReader(data)) @@ -35,7 +35,7 @@ func LoadData(data []byte, cfg interface{}) error { return nil } -func SaveFile(filename string, cfg interface{}) error { +func SaveFile(filename string, cfg any) error { data, err := json.MarshalIndent(cfg, "", "\t") if err != nil { return err diff --git a/pkg/config/merge.go b/pkg/config/merge.go index 3d8193c02..ae4320946 100644 --- a/pkg/config/merge.go +++ b/pkg/config/merge.go @@ -23,7 +23,7 @@ func MergeJSONs(left, right []byte) ([]byte, error) { // Recursively apply a patch to a raw JSON data. // Patch is supposed to be a map, which possibly nests other map objects. -func PatchJSON(left []byte, patch map[string]interface{}) ([]byte, error) { +func PatchJSON(left []byte, patch map[string]any) ([]byte, error) { vLeft, err := parseFragment(left) if err != nil { return nil, err @@ -31,7 +31,7 @@ func PatchJSON(left []byte, patch map[string]interface{}) ([]byte, error) { return json.Marshal(mergeRecursive(vLeft, patch)) } -func parseFragment(input []byte) (parsed interface{}, err error) { +func parseFragment(input []byte) (parsed any, err error) { if len(input) == 0 { // For convenience, we allow empty strings to be passed to the function that merges JSONs. return @@ -42,15 +42,15 @@ func parseFragment(input []byte) (parsed interface{}, err error) { // If one of the elements is not a map, use the new one. // Otherwise, recursively merge map elements. -func mergeRecursive(left, right interface{}) interface{} { +func mergeRecursive(left, right any) any { if left == nil { return right } if right == nil { return left } - mLeft, okLeft := left.(map[string]interface{}) - mRight, okRight := right.(map[string]interface{}) + mLeft, okLeft := left.(map[string]any) + mRight, okRight := right.(map[string]any) if !okLeft || !okRight { return right } diff --git a/pkg/config/merge_test.go b/pkg/config/merge_test.go index 6785534f1..53d8a2116 100644 --- a/pkg/config/merge_test.go +++ b/pkg/config/merge_test.go @@ -51,19 +51,19 @@ func TestMergeJSONs(t *testing.T) { func TestPatchJSON(t *testing.T) { tests := []struct { left string - patch map[string]interface{} + patch map[string]any result string }{ { `{"a":1,"b":2}`, - map[string]interface{}{"b": "string val"}, + map[string]any{"b": "string val"}, `{"a":1,"b":"string val"}`, }, { `{"a":1,"b":2}`, - map[string]interface{}{ - "a": map[string]interface{}{ - "b": map[string]interface{}{ + map[string]any{ + "a": map[string]any{ + "b": map[string]any{ "c": 5, }, }, @@ -72,9 +72,9 @@ func TestPatchJSON(t *testing.T) { }, { `{}`, - map[string]interface{}{ - "a": map[string]interface{}{ - "b": map[string]interface{}{ + map[string]any{ + "a": map[string]any{ + "b": map[string]any{ "c": 0, }, }, -- cgit mrf-deployment