mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00

Lots of people are paying attention to what dependecies we add to their projects now. This just makes things a little cleaner. Resolves #469
37 lines
718 B
Go
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"))
|
|
}
|