本文整理汇总了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation.Schema类的典型用法代码示例。如果您正苦于以下问题:Golang Schema类的具体用法?Golang Schema怎么用?Golang Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Schema类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ValidateSchema
func ValidateSchema(data []byte, schema validation.Schema) error {
if schema == nil {
return nil
}
data, err := yaml.ToJSON(data)
if err != nil {
return fmt.Errorf("error converting to YAML: %v", err)
}
if err := schema.ValidateBytes(data); err != nil {
return fmt.Errorf("error validating data: %v", err)
}
return nil
}
示例2: ResourceFromFile
// ResourceFromFile retrieves the name and namespace from a valid file. If the file does not
// resolve to a known type an error is returned. The returned mapping can be used to determine
// the correct REST endpoint to modify this resource with.
// DEPRECATED: Use resource.Builder
func ResourceFromFile(filename string, typer runtime.ObjectTyper, mapper meta.RESTMapper, schema validation.Schema, cmdVersion string) (mapping *meta.RESTMapping, namespace, name string, data []byte, err error) {
data, err = ReadConfigData(filename)
if err != nil {
return
}
objVersion, kind, err := typer.DataVersionAndKind(data)
if err != nil {
return
}
// TODO: allow unversioned objects?
if len(objVersion) == 0 {
err = fmt.Errorf("the resource in the provided file has no apiVersion defined")
}
err = schema.ValidateBytes(data)
if err != nil {
return
}
// decode using the version stored with the object (allows codec to vary across versions)
mapping, err = mapper.RESTMapping(kind, objVersion)
if err != nil {
return
}
obj, err := mapping.Codec.Decode(data)
if err != nil {
return
}
meta := mapping.MetadataAccessor
namespace, err = meta.Namespace(obj)
if err != nil {
return
}
name, err = meta.Name(obj)
if err != nil {
return
}
// if the preferred API version differs, get a different mapper
if cmdVersion != objVersion {
mapping, err = mapper.RESTMapping(kind, cmdVersion)
}
return
}
示例3: ResourceFromFile
// ResourceFromFile retrieves the name and namespace from a valid file. If the file does not
// resolve to a known type an error is returned. The returned mapping can be used to determine
// the correct REST endpoint to modify this resource with.
func ResourceFromFile(cmd *cobra.Command, filename string, typer runtime.ObjectTyper, mapper meta.RESTMapper, schema validation.Schema) (mapping *meta.RESTMapping, namespace, name string, data []byte) {
configData, err := ReadConfigData(filename)
checkErr(err)
data = configData
objVersion, kind, err := typer.DataVersionAndKind(data)
checkErr(err)
// TODO: allow unversioned objects?
if len(objVersion) == 0 {
checkErr(fmt.Errorf("the resource in the provided file has no apiVersion defined"))
}
err = schema.ValidateBytes(data)
checkErr(err)
// decode using the version stored with the object (allows codec to vary across versions)
mapping, err = mapper.RESTMapping(kind, objVersion)
checkErr(err)
obj, err := mapping.Codec.Decode(data)
checkErr(err)
meta := mapping.MetadataAccessor
namespace, err = meta.Namespace(obj)
checkErr(err)
name, err = meta.Name(obj)
checkErr(err)
// if the preferred API version differs, get a different mapper
version := GetFlagString(cmd, "api-version")
if version != objVersion {
mapping, err = mapper.RESTMapping(kind, version)
checkErr(err)
}
return
}