1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-31 22:46:25 +00:00
Files
rke/util/util.go
2019-01-07 12:07:46 -08:00

54 lines
971 B
Go

package util
import (
"fmt"
"reflect"
"strings"
"github.com/coreos/go-semver/semver"
)
const (
WorkerThreads = 50
)
func StrToSemVer(version string) (*semver.Version, error) {
v, err := semver.NewVersion(strings.TrimPrefix(version, "v"))
if err != nil {
return nil, err
}
return v, nil
}
func GetObjectQueue(l interface{}) chan interface{} {
s := reflect.ValueOf(l)
c := make(chan interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
c <- s.Index(i).Interface()
}
close(c)
return c
}
func ErrList(e []error) error {
if len(e) > 0 {
return fmt.Errorf("%v", e)
}
return nil
}
// UniqueStringSlice - Input slice, retrun slice with unique elements. Will not maintain order.
func UniqueStringSlice(elements []string) []string {
encountered := map[string]bool{}
result := []string{}
for v := range elements {
if !encountered[elements[v]] {
encountered[elements[v]] = true
result = append(result, elements[v])
}
}
return result
}