terraform/builtin/providers/newrelic/helpers.go

38 lines
644 B
Go

package newrelic
import (
"fmt"
"strconv"
"strings"
)
func parseIDs(serializedID string, count int) ([]int, error) {
rawIDs := strings.SplitN(serializedID, ":", count)
if len(rawIDs) != count {
return []int{}, fmt.Errorf("Unable to parse ID %v", serializedID)
}
ids := make([]int, count)
for i, rawID := range rawIDs {
id, err := strconv.ParseInt(rawID, 10, 32)
if err != nil {
return ids, err
}
ids[i] = int(id)
}
return ids, nil
}
func serializeIDs(ids []int) string {
idStrings := make([]string, len(ids))
for i, id := range ids {
idStrings[i] = strconv.Itoa(id)
}
return strings.Join(idStrings, ":")
}