當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Component.SetVersion方法代碼示例

本文整理匯總了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
}
開發者ID:opencontrol,項目名稱:compliance-masonry,代碼行數:39,代碼來源:parse.go


注:本文中的github.com/opencontrol/compliance-masonry/lib/common.Component.SetVersion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。