Skip to content

Commit 3cb3235

Browse files
authored
✨ Generic map and slice serialisers (#622)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description - extended mapstructure decode - add ways to flatten and expand maps ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent 9c7e5fd commit 3cb3235

34 files changed

Lines changed: 1459 additions & 29 deletions

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,5 @@
265265
}
266266
]
267267
},
268-
"generated_at": "2025-05-12T17:01:47Z"
268+
"generated_at": "2025-05-30T10:38:21Z"
269269
}

changes/20250530113842.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:camel: Upgrade dependencies

changes/20250530114030.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:gear: Move dependency on mapstructure to use https://github.com/go-viper/mapstructure as https://github.com/mitchellh/mapstructure is [no longer maintained](https://github.com/go-viper/mapstructure?tab=readme-ov-file#migrating-from-githubcommitchellhmapstructure)

changes/20250530114133.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: [serialization] Added ways to serialise structs into maps or slice

changes/20250530114405.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: [maps] Added ways to expand and flatten maps in a similar fashion to https://github.com/krakend/flatmap and no longer available https://pkg.go.dev/github.com/hashicorp/terraform/flatmap

utils/charset/iconv/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"io"
1212
)
1313

14-
//go:generate mockgen -destination=../../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/charset/$GOPACKAGE ICharsetConverter
14+
//go:generate go tool mockgen -destination=../../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/charset/$GOPACKAGE ICharsetConverter
1515

1616
type ICharsetConverter interface {
1717
// ConvertString converts the charset of an input string

utils/collection/pagination/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"io"
1313
)
1414

15-
//go:generate mockgen -destination=../../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/collection/$GOPACKAGE IStaticPage,IPage,IStaticPageStream,IStream,IIterator,IPaginator,IPaginatorAndPageFetcher,IStreamPaginator,IStreamPaginatorAndPageFetcher
15+
//go:generate go tool mockgen -destination=../../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/collection/$GOPACKAGE IStaticPage,IPage,IStaticPageStream,IStream,IIterator,IPaginator,IPaginatorAndPageFetcher,IStreamPaginator,IStreamPaginatorAndPageFetcher
1616

1717
// IIterator defines an iterator over a collection of items.
1818
type IIterator interface {

utils/collection/parseLists.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package collection
66

77
import (
88
"fmt"
9+
"slices"
910
"strings"
1011
"unicode"
1112

@@ -75,11 +76,9 @@ func ConvertSliceToMap[T comparable](input []T) (pairs map[T]T, err error) {
7576
}
7677

7778
pairs = make(map[T]T, numElements/2)
78-
// TODO use slices.Chunk introduced in go 23 when library is upgraded
79-
for i := 0; i < numElements; i += 2 {
80-
pairs[input[i]] = input[i+1]
79+
for pair := range slices.Chunk(input, 2) {
80+
pairs[pair[0]] = pair[1]
8181
}
82-
8382
return
8483
}
8584

utils/config/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Package config provides utilities to load configuration from an environment and perform validation at load time.
77
package config
88

9-
//go:generate mockgen -destination=../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/$GOPACKAGE IServiceConfiguration,Validator
9+
//go:generate go tool mockgen -destination=../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/$GOPACKAGE IServiceConfiguration,Validator
1010

1111
// IServiceConfiguration defines a typical service configuration.
1212
type IServiceConfiguration interface {

utils/config/service_configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"fmt"
1010
"strings"
1111

12+
"github.com/go-viper/mapstructure/v2"
1213
"github.com/joho/godotenv"
13-
"github.com/mitchellh/mapstructure"
1414
"github.com/spf13/pflag"
1515
"github.com/spf13/viper"
1616

0 commit comments

Comments
 (0)