本文整理汇总了Golang中k8s/io/kubernetes/pkg/util/validation.IsCIdentifier函数的典型用法代码示例。如果您正苦于以下问题:Golang IsCIdentifier函数的具体用法?Golang IsCIdentifier怎么用?Golang IsCIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsCIdentifier函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseEnvs
func parseEnvs(envArray []string) ([]api.EnvVar, error) {
envs := []api.EnvVar{}
for _, env := range envArray {
parts := strings.Split(env, "=")
if len(parts) != 2 || !validation.IsCIdentifier(parts[0]) || len(parts[1]) == 0 {
return nil, fmt.Errorf("invalid env: %v", env)
}
envVar := api.EnvVar{Name: parts[0], Value: parts[1]}
envs = append(envs, envVar)
}
return envs, nil
}
示例2: validateEnv
func validateEnv(vars []kapi.EnvVar) fielderrors.ValidationErrorList {
allErrs := fielderrors.ValidationErrorList{}
for i, ev := range vars {
vErrs := fielderrors.ValidationErrorList{}
if len(ev.Name) == 0 {
vErrs = append(vErrs, fielderrors.NewFieldRequired("name"))
}
if !kvalidation.IsCIdentifier(ev.Name) {
vErrs = append(vErrs, fielderrors.NewFieldInvalid("name", ev.Name, "must match regex "+kvalidation.CIdentifierFmt))
}
allErrs = append(allErrs, vErrs.PrefixIndex(i)...)
}
return allErrs
}
示例3: ValidateStrategyEnv
func ValidateStrategyEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
for i, ev := range vars {
idxPath := fldPath.Index(i)
if len(ev.Name) == 0 {
allErrs = append(allErrs, field.Required(idxPath.Child("name"), ""))
} else if !kvalidation.IsCIdentifier(ev.Name) {
allErrs = append(allErrs, field.Invalid(idxPath.Child("name"), ev.Name, cIdentifierErrorMsg))
}
if ev.ValueFrom != nil {
allErrs = append(allErrs, field.Invalid(idxPath.Child("valueFrom"), ev.ValueFrom, "valueFrom is not supported in build strategy environment variables"))
}
}
return allErrs
}
示例4: validateEnv
func validateEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
for i, ev := range vars {
vErrs := field.ErrorList{}
idxPath := fldPath.Child("name").Index(i)
if len(ev.Name) == 0 {
vErrs = append(vErrs, field.Required(idxPath, ""))
}
if !kvalidation.IsCIdentifier(ev.Name) {
vErrs = append(vErrs, field.Invalid(idxPath, ev.Name, "must match regex "+kvalidation.CIdentifierFmt))
}
allErrs = append(allErrs, vErrs...)
}
return allErrs
}
示例5: validateEnv
func validateEnv(vars []kapi.EnvVar, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
for i, ev := range vars {
vErrs := field.ErrorList{}
idxPath := fldPath.Index(i).Child("name")
if len(ev.Name) == 0 {
vErrs = append(vErrs, field.Required(idxPath, ""))
}
if errs := kvalidation.IsCIdentifier(ev.Name); len(errs) > 0 {
vErrs = append(vErrs, field.Invalid(idxPath, ev.Name, strings.Join(errs, ", ")))
}
allErrs = append(allErrs, vErrs...)
}
return allErrs
}
示例6: parseV1Envs
func parseV1Envs(envArray []string) ([]v1.EnvVar, error) {
envs := []v1.EnvVar{}
for _, env := range envArray {
pos := strings.Index(env, "=")
if pos == -1 {
return nil, fmt.Errorf("invalid env: %v", env)
}
name := env[:pos]
value := env[pos+1:]
if len(name) == 0 || !validation.IsCIdentifier(name) || len(value) == 0 {
return nil, fmt.Errorf("invalid env: %v", env)
}
envVar := v1.EnvVar{Name: name, Value: value}
envs = append(envs, envVar)
}
return envs, nil
}