本文整理汇总了Golang中github.com/opencontrol/compliance-masonry/lib/common.Component.SetVersion方法的典型用法代码示例。如果您正苦于以下问题:Golang Component.SetVersion方法的具体用法?Golang Component.SetVersion怎么用?Golang Component.SetVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/opencontrol/compliance-masonry/lib/common.Component
的用法示例。
在下文中一共展示了Component.SetVersion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseComponent
func parseComponent(componentData []byte, fileName string) (common.Component, error) {
b := Base{}
err := yaml.Unmarshal(componentData, &b)
if err != nil {
// If we have a human friendly BaseComponentParseError, return it.
switch err.(type) {
case BaseComponentParseError:
return nil, err
}
// Otherwise, just return a generic error about the schema.
return nil, fmt.Errorf("Unable to parse component %s. Error: %s", fileName, err.Error())
}
var component common.Component
switch {
case ComponentV2_0_0.EQ(b.SchemaVersion):
c := new(v2.Component)
err = yaml.Unmarshal(componentData, c)
component = c
case ComponentV3_0_0.EQ(b.SchemaVersion):
c := new(v3.Component)
err = yaml.Unmarshal(componentData, c)
component = c
case ComponentV3_1_0.EQ(b.SchemaVersion):
c := new(v31.Component)
err = yaml.Unmarshal(componentData, c)
component = c
default:
return nil, common.ErrUnknownSchemaVersion
}
if err != nil {
return nil, fmt.Errorf("Unable to parse component. Please check component.yaml schema for version %s\n"+
"\tFile: %v\n\tParse error: %v", b.SchemaVersion.String(), fileName, err)
}
// Copy version from base because some versions of the component can not expect to parse directly into it's own struct
// e.g. version 2.0.0 with 2.0 float
component.SetVersion(b.SchemaVersion)
return component, nil
}