Skip to content

Commit b370e64

Browse files
authored
✨ Added message utilities (#10)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Proprietary --> ### Description - made few fixes - added utilities to work with messages - added utilities to paginate through some collections ### 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). Co-authored-by: acabarbaye <[email protected]>
1 parent 804ed89 commit b370e64

35 files changed

+1328
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
SPDX-License-Identifier: Apache-2.0
44
-->
55
# Embedded development services HTTP client utilities

changes/20221229173222.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `[field]` Added conversion utilities for `any`

changes/20221229173247.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `[message]` Added utilities to work with messages

changes/20221229173318.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `[pagination]` Added converters for collections and streams

utils/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

utils/api/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

utils/errors/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

utils/errors/errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
package errors

utils/field/fields.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

@@ -113,6 +113,19 @@ func OptionalString(ptr *string, defaultValue string) string {
113113
return defaultValue
114114
}
115115

116+
// ToOptionalAny returns a pointer to a object.
117+
func ToOptionalAny(a any) *any {
118+
return &a
119+
}
120+
121+
// OptionalAny returns the value of an optional field or else returns defaultValue.
122+
func OptionalAny(ptr *any, defaultValue any) any {
123+
if ptr != nil {
124+
return *ptr
125+
}
126+
return defaultValue
127+
}
128+
116129
// ToOptionalFloat32 returns a pointer to a float32.
117130
func ToOptionalFloat32(i float32) *float32 {
118131
return &i

utils/field/fields_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
2+
* Copyright (C) 2020-2023 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
package field
@@ -185,6 +185,21 @@ func TestOptionalField(t *testing.T) {
185185
return OptionalDuration(ptr, a2.(time.Duration))
186186
},
187187
},
188+
{
189+
fieldType: "Any",
190+
value: faker.Sentence(),
191+
defaultValue: time.Now(),
192+
setFunction: func(a any) any {
193+
return ToOptionalAny(a)
194+
},
195+
getFunction: func(a any, a2 any) any {
196+
var ptr *any
197+
if a != nil {
198+
ptr = a.(*any)
199+
}
200+
return OptionalAny(ptr, a2)
201+
},
202+
},
188203
}
189204
for i := range tests {
190205
test := tests[i]

0 commit comments

Comments
 (0)