github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/newrelic/helpers.go (about)

     1  package newrelic
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  func parseIDs(serializedID string, count int) ([]int, error) {
    10  	rawIDs := strings.SplitN(serializedID, ":", count)
    11  	if len(rawIDs) != count {
    12  		return []int{}, fmt.Errorf("Unable to parse ID %v", serializedID)
    13  	}
    14  
    15  	ids := make([]int, count)
    16  
    17  	for i, rawID := range rawIDs {
    18  		id, err := strconv.ParseInt(rawID, 10, 32)
    19  		if err != nil {
    20  			return ids, err
    21  		}
    22  
    23  		ids[i] = int(id)
    24  	}
    25  
    26  	return ids, nil
    27  }
    28  
    29  func serializeIDs(ids []int) string {
    30  	idStrings := make([]string, len(ids))
    31  
    32  	for i, id := range ids {
    33  		idStrings[i] = strconv.Itoa(id)
    34  	}
    35  
    36  	return strings.Join(idStrings, ":")
    37  }