github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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 const ( 12 // https://developer.github.com/guides/traversing-with-pagination/#basics-of-pagination 13 maxPerPage = 100 14 ) 15 16 func toGithubID(id string) int { 17 githubID, _ := strconv.Atoi(id) 18 return githubID 19 } 20 21 func fromGithubID(id *int) string { 22 return strconv.Itoa(*id) 23 } 24 25 func validateValueFunc(values []string) schema.SchemaValidateFunc { 26 return func(v interface{}, k string) (we []string, errors []error) { 27 value := v.(string) 28 valid := false 29 for _, role := range values { 30 if value == role { 31 valid = true 32 break 33 } 34 } 35 36 if !valid { 37 errors = append(errors, fmt.Errorf("%s is an invalid value for argument %s", value, k)) 38 } 39 return 40 } 41 } 42 43 // return the pieces of id `a:b` as a, b 44 func parseTwoPartID(id string) (string, string) { 45 parts := strings.SplitN(id, ":", 2) 46 return parts[0], parts[1] 47 } 48 49 // format the strings into an id `a:b` 50 func buildTwoPartID(a, b *string) string { 51 return fmt.Sprintf("%s:%s", *a, *b) 52 }