func parseValueList(str, sep string, valuep interface{}) error {
	var value interface{}
	switch valuep.(type) {
	case *idset.IDSet:
		value = idset.NewIDSet()
	case *[]int:
		value = []int{}
	case *[]uint:
		value = []uint{}
	case *[]int8:
		value = []int8{}
	case *[]uint8:
		value = []uint8{}
	case *[]int16:
		value = []int16{}
	case *[]uint16:
		value = []uint16{}
	case *[]int32:
		value = []int32{}
	case *[]uint32:
		value = []uint32{}
	case *[]int64:
		value = []int64{}
	case *[]uint64:
		value = []uint64{}
	default:
		return fmt.Errorf("invalid slice value type: %T", valuep)
	}
	for _, s := range strings.Split(str, sep) {
		if s == "" {
			break
		}
		switch value.(type) {
		case idset.IDSet:
			if rng := strings.Split(s, "-"); len(rng) == 1 {
				id, err := strconv.Atoi(s)
				if err != nil {
					return fmt.Errorf("invalid entry '%s': %v", s, err)
				}
				value.(idset.IDSet).Add(idset.ID(id))
			} else {
				beg, err := strconv.Atoi(rng[0])
				if err != nil {
					return fmt.Errorf("invalid entry '%s': %v", s, err)
				}
				end, err := strconv.Atoi(rng[1])
				if err != nil {
					return fmt.Errorf("invalid entry '%s': %v", s, err)
				}
				for id := beg; id <= end; id++ {
					value.(idset.IDSet).Add(idset.ID(id))
				}
			}
		case []int, []int8, []int16, []int32, []int64:
			v, err := strconv.ParseInt(s, 0, 0)
			if err != nil {
				return fmt.Errorf("invalid entry '%s': %v", s, err)
			}
			switch value.(type) {
			case []int:
				value = append(value.([]int), int(v))
			case []int8:
				value = append(value.([]int8), int8(v))
			case []int16:
				value = append(value.([]int16), int16(v))
			case []int32:
				value = append(value.([]int32), int32(v))
			case []int64:
				value = append(value.([]int64), v)
			}
		case []uint, []uint8, []uint16, []uint32, []uint64:
			v, err := strconv.ParseUint(s, 0, 0)
			if err != nil {
				return fmt.Errorf("invalid entry '%s': %v", s, err)
			}
			switch value.(type) {
			case []uint:
				value = append(value.([]uint), uint(v))
			case []uint8:
				value = append(value.([]uint8), uint8(v))
			case []uint16:
				value = append(value.([]uint16), uint16(v))
			case []uint32:
				value = append(value.([]uint32), uint32(v))
			case []uint64:
				value = append(value.([]uint64), v)
			}
		}
	}
	switch valuep.(type) {
	case *idset.IDSet:
		*valuep.(*idset.IDSet) = value.(idset.IDSet)
	case *[]int:
		*valuep.(*[]int) = value.([]int)
	case *[]uint:
		*valuep.(*[]uint) = value.([]uint)
	case *[]int8:
		*valuep.(*[]int8) = value.([]int8)
	case *[]uint8:
		*valuep.(*[]uint8) = value.([]uint8)
	case *[]int16:
		*valuep.(*[]int16) = value.([]int16)
	case *[]uint16:
		*valuep.(*[]uint16) = value.([]uint16)
	case *[]int32:
		*valuep.(*[]int32) = value.([]int32)
	case *[]uint32:
		*valuep.(*[]uint32) = value.([]uint32)
	case *[]int64:
		*valuep.(*[]int64) = value.([]int64)
	case *[]uint64:
		*valuep.(*[]uint64) = value.([]uint64)
	}
	return nil
}
Parse a list of values from a string into a slice.
package sysfs
import (
	"fmt"
	idset "github.com/intel/goresctrl/pkg/utils"
	"io/ioutil"
	"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
	"os"
	"path/filepath"
	"strconv"
	"strings"
)
func getEnumeratedID(name string) idset.ID {
	id := 0
	base := 1
	for idx := len(name) - 1; idx > 0; idx-- {
		d := name[idx]
		if '0' <= d && d <= '9' {
			id += base * (int(d) - '0')
			base *= 10
		} else {
			if base > 1 {
				return idset.ID(id)
			}
			return idset.ID(-1)
		}
	}
	return idset.ID(-1)
}
func readSysfsEntry(base, entry string, ptr interface{}, args ...interface{}) (string, error) {
	var buf string
	path := filepath.Join(base, entry)
	blob, err := ioutil.ReadFile(path)
	if err != nil {
		return "", sysfsError(path, "failed to read sysfs entry: %v", err)
	}
	buf = strings.Trim(string(blob), "\n")
	if ptr == interface{}(nil) {
		return buf, nil
	}
	switch ptr.(type) {
	case *string, *int, *uint, *int8, *uint8, *int16, *uint16, *int32, *uint32, *int64, *uint64:
		err := parseValue(buf, ptr)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
		return buf, nil
	case *idset.IDSet, *[]int, *[]uint, *[]int8, *[]uint8, *[]int16, *[]uint16, *[]int32, *[]uint32, *[]int64, *[]uint64:
		sep, err := getSeparator(" ", args)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
		err = parseValueList(buf, sep, ptr)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
		return buf, nil
	case *EPP:
		*ptr.(*EPP) = EPPFromString(buf)
		return buf, nil
	}
	return "", sysfsError(path, "unsupported sysfs entry type %T", ptr)
}
func writeSysfsEntry(base, entry string, val, oldp interface{}, args ...interface{}) (string, error) {
	var buf, old string
	var err error
	if oldp != nil {
		if old, err = readSysfsEntry(base, entry, oldp, args...); err != nil {
			return "", err
		}
	}
	path := filepath.Join(base, entry)
	switch val.(type) {
	case string, int, uint, int8, uint8, int16, uint16, int32, uint32, int64, uint64:
		buf, err = formatValue(val)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
	case idset.IDSet, []int, []uint, []int8, []uint8, []int16, []uint16, []int32, []uint32, []int64, []uint64:
		sep, err := getSeparator(" ", args)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
		buf, err = formatValueList(sep, val)
		if err != nil {
			return "", sysfsError(path, "%v", err)
		}
	default:
		return "", sysfsError(path, "unsupported sysfs entry type %T", val)
	}
	f, err := os.OpenFile(path, os.O_WRONLY, 0)
	if err != nil {
		return "", sysfsError(path, "cannot open: %v", err)
	}
	defer f.Close()
	if _, err = f.Write([]byte(buf + "\n")); err != nil {
		return "", sysfsError(path, "cannot write: %v", err)
	}
	return old, nil
}
func getSeparator(defaultVal string, args []interface{}) (string, error) {
	switch len(args) {
	case 0:
		return defaultVal, nil
	case 1:
		return args[0].(string), nil
	}
	return "", fmt.Errorf("invalid separator (%v), 1 expected, %d given", args, len(args))
}
func parseValue(str string, value interface{}) error {
	switch value.(type) {
	case *string:
		*value.(*string) = str
	case *int, *int8, *int16, *int32, *int64:
		v, err := strconv.ParseInt(str, 0, 0)
		if err != nil {
			return fmt.Errorf("invalid entry '%s': %v", str, err)
		}
		switch value.(type) {
		case *int:
			*value.(*int) = int(v)
		case *int8:
			*value.(*int8) = int8(v)
		case *int16:
			*value.(*int16) = int16(v)
		case *int32:
			*value.(*int32) = int32(v)
		case int64:
			*value.(*int64) = v
		}
	case *uint, *uint8, *uint16, *uint32, *uint64:
		v, err := strconv.ParseUint(str, 0, 0)
		if err != nil {
			return fmt.Errorf("invalid entry: '%s': %v", str, err)
		}
		switch value.(type) {
		case *uint:
			*value.(*uint) = uint(v)
		case *uint8:
			*value.(*uint8) = uint8(v)
		case *uint16:
			*value.(*uint16) = uint16(v)
		case *uint32:
			*value.(*uint32) = uint32(v)
		case *uint64:
			*value.(*uint64) = v
		}
	}
	return nil
}