package util import ( "math/rand" "regexp" "strings" ) // FindInSlice finds value in a slice func FindInSlice(slice []string, val string) bool { for _, item := range slice { if item == val { return true } } return false } // ValuesString concatenate all values of a map split by comma func ValuesString(m map[string]string) string { values := make([]string, 0, len(m)) for _, v := range m { values = append(values, v) } return strings.Join(values, ", ") } var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)") var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])") // ToSnakeCase converts string to snake case func ToSnakeCase(str string) string { snake := matchFirstCap.ReplaceAllString(str, "${1}_${2}") snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}") return strings.ToLower(snake) } const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1<