本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/util.IsCIdentifier函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsCIdentifier函數的具體用法?Golang IsCIdentifier怎麽用?Golang IsCIdentifier使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsCIdentifier函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestServiceRegistryMakeLinkVariables
func TestServiceRegistryMakeLinkVariables(t *testing.T) {
service := api.Service{
JSONBase: api.JSONBase{ID: "foo"},
Selector: map[string]string{"bar": "baz"},
ContainerPort: util.IntOrString{Kind: util.IntstrString, StrVal: "a-b-c"},
}
vars := makeLinkVariables(service, "mars")
for _, v := range vars {
if !util.IsCIdentifier(v.Name) {
t.Errorf("Environment variable name is not valid: %v", v.Name)
}
}
}
示例2: validateEnv
func validateEnv(vars []EnvVar) errorList {
allErrs := errorList{}
for i := range vars {
ev := &vars[i] // so we can set default values
if len(ev.Name) == 0 {
allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name))
}
if !util.IsCIdentifier(ev.Name) {
allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name))
}
}
return allErrs
}
示例3: 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 !util.IsCIdentifier(ev.Name) {
vErrs = append(vErrs, fielderrors.NewFieldInvalid("name", ev.Name, "must match regex "+util.CIdentifierFmt))
}
allErrs = append(allErrs, vErrs.PrefixIndex(i)...)
}
return allErrs
}
示例4: validateEnv
func validateEnv(vars []api.EnvVar) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
for i, ev := range vars {
vErrs := errs.ValidationErrorList{}
if len(ev.Name) == 0 {
vErrs = append(vErrs, errs.NewFieldRequired("name", ev.Name))
}
if !util.IsCIdentifier(ev.Name) {
vErrs = append(vErrs, errs.NewFieldInvalid("name", ev.Name, cIdentifierErrorMsg))
}
allErrs = append(allErrs, vErrs.PrefixIndex(i)...)
}
return allErrs
}
示例5: validateEnv
func validateEnv(vars []api.EnvVar) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
for i := range vars {
vErrs := errs.ValidationErrorList{}
ev := &vars[i] // so we can set default values
if len(ev.Name) == 0 {
vErrs = append(vErrs, errs.NewFieldRequired("name", ev.Name))
}
if !util.IsCIdentifier(ev.Name) {
vErrs = append(vErrs, errs.NewFieldInvalid("name", ev.Name, ""))
}
allErrs = append(allErrs, vErrs.PrefixIndex(i)...)
}
return allErrs
}
示例6: validateEnv
func validateEnv(vars []EnvVar) error {
for i := range vars {
ev := &vars[i] // so we can set default values
if len(ev.Name) == 0 {
// Backwards compat.
if len(ev.Key) == 0 {
return makeInvalidError("EnvVar.Name", ev.Name)
}
glog.Warning("DEPRECATED: EnvVar.Key has been replaced by EnvVar.Name")
ev.Name = ev.Key
ev.Key = ""
}
if !util.IsCIdentifier(ev.Name) {
return makeInvalidError("EnvVar.Name", ev.Name)
}
}
return nil
}
示例7: TestServiceRegistryMakeLinkVariables
func TestServiceRegistryMakeLinkVariables(t *testing.T) {
service := api.Service{
JSONBase: api.JSONBase{ID: "foo-bar"},
Selector: map[string]string{"bar": "baz"},
ContainerPort: util.IntOrString{Kind: util.IntstrString, StrVal: "a-b-c"},
}
registry := registrytest.NewServiceRegistry()
registry.List = api.ServiceList{
Items: []api.Service{service},
}
machine := "machine"
vars, err := GetServiceEnvironmentVariables(registry, machine)
if err != nil {
t.Errorf("Unexpected err: %v", err)
}
for _, v := range vars {
if !util.IsCIdentifier(v.Name) {
t.Errorf("Environment variable name is not valid: %v", v.Name)
}
}
}
示例8: validateEnv
func validateEnv(vars []EnvVar) errorList {
allErrs := errorList{}
for i := range vars {
ev := &vars[i] // so we can set default values
if len(ev.Name) == 0 {
// Backwards compat.
if len(ev.Key) == 0 {
allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name))
} else {
glog.Warning("DEPRECATED: EnvVar.Key has been replaced by EnvVar.Name")
ev.Name = ev.Key
ev.Key = ""
}
}
if !util.IsCIdentifier(ev.Name) {
allErrs.Append(makeInvalidError("EnvVar.Name", ev.Name))
}
}
return allErrs
}