forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
47 lines (39 loc) · 928 Bytes
/
util.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
44
45
46
47
package github
import (
"fmt"
"strconv"
"strings"
"github.com/hashicorp/terraform/helper/schema"
)
func toGithubID(id string) int {
githubID, _ := strconv.Atoi(id)
return githubID
}
func fromGithubID(id *int) string {
return strconv.Itoa(*id)
}
func validateValueFunc(values []string) schema.SchemaValidateFunc {
return func(v interface{}, k string) (we []string, errors []error) {
value := v.(string)
valid := false
for _, role := range values {
if value == role {
valid = true
break
}
}
if !valid {
errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k))
}
return
}
}
// return the pieces of id `a:b` as a, b
func parseTwoPartID(id string) (string, string) {
parts := strings.SplitN(id, ":", 2)
return parts[0], parts[1]
}
// format the strings into an id `a:b`
func buildTwoPartID(a, b *string) string {
return fmt.Sprintf("%s:%s", *a, *b)
}