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")
|
|
|
|
}
|
|
|
|
|
2023-03-27 22:26:29 +00:00
|
|
|
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
|
|
|
|
}
|
2023-03-27 22:26:29 +00:00
|
|
|
|
|
|
|
func isLetter(r rune) bool {
|
|
|
|
l := unicode.ToLower(r)
|
2023-04-11 22:36:37 +00:00
|
|
|
return (l >= 'a' && l <= 'f')
|
2023-03-27 22:26:29 +00:00
|
|
|
}
|