add MustString
This commit is contained in:
11
utils/ext.go
11
utils/ext.go
@@ -1,6 +1,8 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -33,3 +35,12 @@ func ParseParams(in map[string]string) map[string]any {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func MustString(value string) (string, error) {
|
||||
var workspacePattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
|
||||
value = strings.ToLower(strings.TrimSpace(value))
|
||||
if !workspacePattern.MatchString(value) {
|
||||
return "", fmt.Errorf("workspace must match %s", workspacePattern.String())
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user