-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
set.go
43 lines (34 loc) · 810 Bytes
/
set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package set
import (
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func HashInt(v interface{}) int {
return hashcode.String(strconv.Itoa(v.(int)))
}
func HashStringIgnoreCase(v interface{}) int {
return hashcode.String(strings.ToLower(v.(string)))
}
func FromInt32Slice(slice []int32) *schema.Set {
set := &schema.Set{F: HashInt}
for _, v := range slice {
set.Add(int(v))
}
return set
}
func ToSliceInt32P(set *schema.Set) *[]int32 {
var slice []int32
for _, m := range set.List() {
slice = append(slice, int32(m.(int)))
}
return &slice
}
func FromStringSlice(slice []string) *schema.Set {
set := &schema.Set{F: schema.HashString}
for _, v := range slice {
set.Add(v)
}
return set
}