github.com/richardbowden/terraform@v0.6.12-0.20160901200758-30ea22c25211/builtin/providers/github/util.go (about) 1 package github 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 8 "github.com/hashicorp/terraform/helper/schema" 9 ) 10 11 func toGithubID(id string) int { 12 githubID, _ := strconv.Atoi(id) 13 return githubID 14 } 15 16 func fromGithubID(id *int) string { 17 return strconv.Itoa(*id) 18 } 19 20 func validateValueFunc(values []string) schema.SchemaValidateFunc { 21 return func(v interface{}, k string) (we []string, errors []error) { 22 value := v.(string) 23 valid := false 24 for _, role := range values { 25 if value == role { 26 valid = true 27 break 28 } 29 } 30 31 if !valid { 32 errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k)) 33 } 34 return 35 } 36 } 37 38 // return the pieces of id `a:b` as a, b 39 func parseTwoPartID(id string) (string, string) { 40 parts := strings.SplitN(id, ":", 2) 41 return parts[0], parts[1] 42 } 43 44 // format the strings into an id `a:b` 45 func buildTwoPartID(a, b *string) string { 46 return fmt.Sprintf("%s:%s", *a, *b) 47 }