@@ -17,7 +17,18 @@ import (
17
17
"google.golang.org/protobuf/types/known/structpb"
18
18
)
19
19
20
- func FromStringSlice (slice []string ) types.List {
20
+ func FromStringSliceToSet (slice []string ) types.Set {
21
+ if slice == nil {
22
+ return types .SetNull (types .StringType )
23
+ }
24
+ fields := make ([]attr.Value , 0 )
25
+ for _ , v := range slice {
26
+ fields = append (fields , types .StringValue (v ))
27
+ }
28
+ return types .SetValueMust (types .StringType , fields )
29
+ }
30
+
31
+ func FromStringSliceToList (slice []string ) types.List {
21
32
if slice == nil {
22
33
return types .ListNull (types .StringType )
23
34
}
@@ -28,12 +39,12 @@ func FromStringSlice(slice []string) types.List {
28
39
return types .ListValueMust (types .StringType , fields )
29
40
}
30
41
31
- // FromStringList converts a Settings_StringList to a types.List
32
- func FromStringList (sl * pb.Settings_StringList ) types.List {
42
+ // FromStringListToSet converts a Settings_StringList to a types.List
43
+ func FromStringListToSet (sl * pb.Settings_StringList ) types.Set {
33
44
if sl == nil {
34
- return types .ListNull (types .StringType )
45
+ return types .SetNull (types .StringType )
35
46
}
36
- return FromStringSlice (sl .Values )
47
+ return FromStringSliceToSet (sl .Values )
37
48
}
38
49
39
50
// FromStringMap converts a map[string]string to a types.Map
@@ -49,14 +60,14 @@ func FromStringMap(m map[string]string) types.Map {
49
60
}
50
61
51
62
// ToStringList converts a types.List to Settings_StringList and handles diagnostics internally
52
- func ToStringList (ctx context.Context , dst * * pb.Settings_StringList , list types.List , diagnostics * diag.Diagnostics ) {
53
- if list .IsNull () {
63
+ func ToStringListFromSet (ctx context.Context , dst * * pb.Settings_StringList , set types.Set , diagnostics * diag.Diagnostics ) {
64
+ if set .IsNull () {
54
65
* dst = nil
55
66
return
56
67
}
57
68
58
69
var values []string
59
- diagnostics .Append (list .ElementsAs (ctx , & values , false )... )
70
+ diagnostics .Append (set .ElementsAs (ctx , & values , false )... )
60
71
if ! diagnostics .HasError () {
61
72
* dst = & pb.Settings_StringList {Values : values }
62
73
}
@@ -76,8 +87,19 @@ func ToStringMap(ctx context.Context, dst *map[string]string, m types.Map, diagn
76
87
}
77
88
}
78
89
79
- // ToStringSlice converts a types.List to string slice and handles diagnostics internally
80
- func ToStringSlice (ctx context.Context , dst * []string , list types.List , diagnostics * diag.Diagnostics ) {
90
+ func ToStringSliceFromSet (ctx context.Context , dst * []string , set types.Set , diagnostics * diag.Diagnostics ) {
91
+ * dst = make ([]string , 0 )
92
+ if ! set .IsNull () {
93
+ var values []string
94
+ diagnostics .Append (set .ElementsAs (ctx , & values , false )... )
95
+ if ! diagnostics .HasError () {
96
+ * dst = values
97
+ }
98
+ }
99
+ }
100
+
101
+ // ToStringSliceFromList converts a types.List to string slice and handles diagnostics internally
102
+ func ToStringSliceFromList (ctx context.Context , dst * []string , list types.List , diagnostics * diag.Diagnostics ) {
81
103
* dst = make ([]string , 0 )
82
104
if ! list .IsNull () {
83
105
var values []string
0 commit comments