Files
webrtc/internal/util/util.go
Sean DuBois 43604d5491 Remove pkg/errors dependency
Lots of people are paying attention to what dependecies we add to their
projects now. This just makes things a little cleaner.

Resolves #469
2019-03-06 09:34:10 -08:00

37 lines
718 B
Go

package util
import (
"fmt"
"math/rand"
"strings"
"time"
)
// RandSeq generates a random alpha numeric sequence of the requested length
func RandSeq(n int) string {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[r.Intn(len(letters))]
}
return string(b)
}
// FlattenErrs flattens multiple errors into one
func FlattenErrs(errs []error) error {
var errstrings []string
for _, err := range errs {
if err != nil {
errstrings = append(errstrings, err.Error())
}
}
if len(errstrings) == 0 {
return nil
}
return fmt.Errorf(strings.Join(errstrings, "\n"))
}