Commit df85a80
authored
feat(go-runtime): add helper functions for the new interface type (#4936)
### Description
Some of our L1 resources will start to take array of interfaces(`*[]interface{}`) instead of (`*[]*string`) as props same applies for Numbers. This PR creating multiple helper functions that can help to make customer life easier.
### L1 Example
[CfnUserProps](https://pkg.go.dev/github.com/aws/aws-cdk-go/awscdk/v2/awsiam#CfnUserProps) has now
```
ManagedPolicyArns *[]*[string](https://pkg.go.dev/builtin#string) `field:"optional" json:"managedPolicyArns" yaml:"managedPolicyArns"`
```
will change to
```
ManagedPolicyArns *[]interface{}`field:"optional" json:"managedPolicyArns" yaml:"managedPolicyArns"`
```
### Helper Functions Usage Example
#### Use Case 1
If you before was using `jsii.Strings()` or `jsii.Numbers()`
```
&CfnUserProps{
ManagedPolicyArns: jsii.Strings("arn1", "arn2"),
}
```
Rename function to use `jsii.AnyStrings()` like this
```
&CfnUserProps{
ManagedPolicyArns: jsii.AnyStrings("arn1", "arn2"),
}
```
#### Use Case 2
If you manually were creating the strings using without `jsii.Strings` syntax
```
func Arns() *[]*string {
a := "arn:aws:s3:::bucket1"
b := "arn:aws:s3:::bucket2"
return &[]*string{&a, &b}
}
&CfnUserProps{
ManagedPolicyArns: Arns(),
}
```
Wrap it with `jsii.AnySlice()` like this
```
&CfnUserProps{
ManagedPolicyArns: jsii.AnySlice(Arns()),
}
```
---
By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].
[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.01 parent e91291d commit df85a80
File tree
2 files changed
+69
-0
lines changed- packages/@jsii/go-runtime/jsii-runtime-go
2 files changed
+69
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| |||
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
0 commit comments