sharedutils/osutils/data.go

34 lines
544 B
Go
Raw Normal View History

2023-03-26 21:17:39 +00:00
package osutils
import (
"github.com/pkg/errors"
"unicode"
)
func UuidValidate(uuid string) error {
if len(uuid) != 36 {
return errors.New("uuid length not valid")
}
for i, r := range uuid {
switch i {
case 8, 13, 18, 23:
if r != '-' {
return errors.New("uuid separator not valid")
}
break
default:
if !isLetter(r) && !unicode.IsDigit(r) {
return errors.Errorf("uuid char on %i not valid", i)
}
2023-03-26 21:17:39 +00:00
}
}
return nil
}
func isLetter(r rune) bool {
l := unicode.ToLower(r)
return (l >= 'a' && l <= 'f')
}