• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang report.ReportFromError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/coreos/ignition/config/validate/report.ReportFromError函数的典型用法代码示例。如果您正苦于以下问题:Golang ReportFromError函数的具体用法?Golang ReportFromError怎么用?Golang ReportFromError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ReportFromError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Parse

func Parse(data []byte) (types.Config, report.Report) {
	var cfg types.Config
	var r report.Report

	if err := yaml.Unmarshal(data, &cfg); err != nil {
		return types.Config{}, report.ReportFromError(err, report.EntryError)
	}

	nodes := yaml.UnmarshalToNode(data)
	if nodes == nil {
		r.Add(report.Entry{
			Kind:    report.EntryWarning,
			Message: "Configuration is empty",
		})
		r.Merge(validate.ValidateWithoutSource(reflect.ValueOf(cfg)))
	} else {
		root, err := fromYamlDocumentNode(*nodes)
		if err != nil {
			return types.Config{}, report.ReportFromError(err, report.EntryError)
		}

		r.Merge(validate.Validate(reflect.ValueOf(cfg), root, nil))
	}

	if r.IsFatal() {
		return types.Config{}, r
	}
	return cfg, r
}
开发者ID:coreos,项目名称:fuze,代码行数:29,代码来源:config.go


示例2: Validate

func (f Filesystem) Validate() report.Report {
	if f.Mount == nil && f.Path == nil {
		return report.ReportFromError(ErrFilesystemNoMountPath, report.EntryError)
	}
	if f.Mount != nil && f.Path != nil {
		return report.ReportFromError(ErrFilesystemMountAndPath, report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:9,代码来源:filesystem.go


示例3: Validate

func (v IgnitionVersion) Validate() report.Report {
	if MaxVersion.Major > v.Major {
		return report.ReportFromError(ErrOldVersion, report.EntryError)
	}
	if MaxVersion.LessThan(semver.Version(v)) {
		return report.ReportFromError(ErrNewVersion, report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:9,代码来源:ignition.go


示例4: Validate

func (d PartitionTypeGUID) Validate() report.Report {
	ok, err := regexp.MatchString("^(|[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12})$", string(d))
	if err != nil {
		return report.ReportFromError(fmt.Errorf("error matching type-guid regexp: %v", err), report.EntryError)
	}
	if !ok {
		return report.ReportFromError(fmt.Errorf(`partition type-guid must have the form "01234567-89AB-CDEF-EDCB-A98765432101", got: %q`, string(d)), report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:10,代码来源:partition.go


示例5: Parse

// Parse parses the raw config into a types.Config struct and generates a report of any
// errors, warnings, info, and deprecations it encountered
func Parse(rawConfig []byte) (types.Config, report.Report, error) {
	switch majorVersion(rawConfig) {
	case 1:
		config, err := ParseFromV1(rawConfig)
		if err != nil {
			return types.Config{}, report.ReportFromError(err, report.EntryError), err
		}

		return config, report.ReportFromError(ErrDeprecated, report.EntryDeprecated), nil
	default:
		return ParseFromLatest(rawConfig)
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:15,代码来源:config.go


示例6: Validate

func (h Hash) Validate() report.Report {
	var hash crypto.Hash
	switch h.Function {
	case "sha512":
		hash = crypto.SHA512
	default:
		return report.ReportFromError(ErrHashUnrecognized, report.EntryError)
	}

	if len(h.Sum) != hex.EncodedLen(hash.Size()) {
		return report.ReportFromError(ErrHashWrongSize, report.EntryError)
	}

	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:15,代码来源:hash.go


示例7: TestFilesystemFormatValidate

func TestFilesystemFormatValidate(t *testing.T) {
	type in struct {
		format FilesystemFormat
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{format: FilesystemFormat("ext4")},
			out: out{},
		},
		{
			in:  in{format: FilesystemFormat("btrfs")},
			out: out{},
		},
		{
			in:  in{format: FilesystemFormat("")},
			out: out{err: ErrFilesystemInvalidFormat},
		},
	}

	for i, test := range tests {
		err := test.in.format.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:33,代码来源:filesystem_test.go


示例8: Validate

func (n Raid) Validate() report.Report {
	switch n.Level {
	case "linear", "raid0", "0", "stripe":
		if n.Spares != 0 {
			return report.ReportFromError(fmt.Errorf("spares unsupported for %q arrays", n.Level), report.EntryError)
		}
	case "raid1", "1", "mirror":
	case "raid4", "4":
	case "raid5", "5":
	case "raid6", "6":
	case "raid10", "10":
	default:
		return report.ReportFromError(fmt.Errorf("unrecognized raid level: %q", n.Level), report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:16,代码来源:raid.go


示例9: TestSystemdUnitNameValidate

func TestSystemdUnitNameValidate(t *testing.T) {
	type in struct {
		unit SystemdUnitName
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{unit: SystemdUnitName("test.service")},
			out: out{err: nil},
		},
		{
			in:  in{unit: SystemdUnitName("test.socket")},
			out: out{err: nil},
		},
		{
			in:  in{unit: SystemdUnitName("test.blah")},
			out: out{err: errors.New("invalid systemd unit extension")},
		},
	}

	for i, test := range tests {
		err := test.in.unit.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:33,代码来源:unit_test.go


示例10: Validate

func (n SystemdUnitDropInName) Validate() report.Report {
	switch filepath.Ext(string(n)) {
	case ".conf":
		return report.Report{}
	default:
		return report.ReportFromError(errors.New("invalid systemd unit drop-in extension"), report.EntryError)
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:8,代码来源:unit.go


示例11: Validate

func (u Url) Validate() report.Report {
	// Empty url is valid, indicates an empty file
	if u.String() == "" {
		return report.Report{}
	}
	switch url.URL(u).Scheme {
	case "http", "https", "oem":
		return report.Report{}
	case "data":
		if _, err := dataurl.DecodeString(u.String()); err != nil {
			return report.ReportFromError(err, report.EntryError)
		}
		return report.Report{}
	default:
		return report.ReportFromError(ErrInvalidScheme, report.EntryError)
	}
}
开发者ID:hashicorp,项目名称:terraform,代码行数:17,代码来源:url.go


示例12: Validate

func (c Compression) Validate() report.Report {
	switch c {
	case "", "gzip":
	default:
		return report.ReportFromError(ErrCompressionInvalid, report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:8,代码来源:compression.go


示例13: Validate

func (u Url) Validate() report.Report {
	// Empty url is valid, indicates an empty file
	if u.String() == "" {
		return report.Report{}
	}
	switch url.URL(u).Scheme {
	case "http", "https", "oem", "data":
		return report.Report{}
	}

	return report.ReportFromError(ErrInvalidScheme, report.EntryError)
}
开发者ID:coreos,项目名称:fuze,代码行数:12,代码来源:url.go


示例14: TestURLValidate

func TestURLValidate(t *testing.T) {
	type in struct {
		u string
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{u: ""},
			out: out{},
		},
		{
			in:  in{u: "http://example.com"},
			out: out{},
		},
		{
			in:  in{u: "https://example.com"},
			out: out{},
		},
		{
			in:  in{u: "oem:///foobar"},
			out: out{},
		},
		{
			in:  in{u: "data:,example%20file%0A"},
			out: out{},
		},
		{
			in:  in{u: "bad://"},
			out: out{err: ErrInvalidScheme},
		},
	}

	for i, test := range tests {
		u, err := url.Parse(test.in.u)
		if err != nil {
			t.Errorf("URL failed to parse. This is an error with the test")
		}
		r := Url(*u).Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), r) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, r)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:49,代码来源:url_test.go


示例15: TestFileValidate

func TestFileValidate(t *testing.T) {
	type in struct {
		mode FileMode
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{mode: FileMode(0)},
			out: out{},
		},
		{
			in:  in{mode: FileMode(0644)},
			out: out{},
		},
		{
			in:  in{mode: FileMode(01755)},
			out: out{},
		},
		{
			in:  in{mode: FileMode(07777)},
			out: out{},
		},
		{
			in:  in{mode: FileMode(010000)},
			out: out{err: ErrFileIllegalMode},
		},
	}

	for i, test := range tests {
		err := test.in.mode.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:41,代码来源:file_test.go


示例16: TestPathValidate

func TestPathValidate(t *testing.T) {
	type in struct {
		device Path
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{device: Path("/good/path")},
			out: out{},
		},
		{
			in:  in{device: Path("/name")},
			out: out{},
		},
		{
			in:  in{device: Path("/this/is/a/fairly/long/path/to/a/device.")},
			out: out{},
		},
		{
			in:  in{device: Path("/this one has spaces")},
			out: out{},
		},
		{
			in:  in{device: Path("relative/path")},
			out: out{err: ErrPathRelative},
		},
	}

	for i, test := range tests {
		err := test.in.device.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:41,代码来源:path_test.go


示例17: TestHashValidate

func TestHashValidate(t *testing.T) {
	type in struct {
		hash Hash
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{hash: Hash{}},
			out: out{err: ErrHashUnrecognized},
		},
		{
			in:  in{hash: Hash{Function: "xor"}},
			out: out{err: ErrHashUnrecognized},
		},
		{
			in:  in{hash: Hash{Function: "sha512", Sum: "123"}},
			out: out{err: ErrHashWrongSize},
		},
		{
			in:  in{hash: Hash{Function: "sha512", Sum: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}},
			out: out{},
		},
	}

	for i, test := range tests {
		err := test.in.hash.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:37,代码来源:hash_test.go


示例18: TestFilesystemValidate

func TestFilesystemValidate(t *testing.T) {
	type in struct {
		filesystem Filesystem
	}
	type out struct {
		err error
	}

	tests := []struct {
		in  in
		out out
	}{
		{
			in:  in{filesystem: Filesystem{Mount: &FilesystemMount{Device: "/foo", Format: "ext4"}}},
			out: out{},
		},
		{
			in:  in{filesystem: Filesystem{Path: func(p Path) *Path { return &p }("/mount")}},
			out: out{},
		},
		{
			in:  in{filesystem: Filesystem{Path: func(p Path) *Path { return &p }("/mount"), Mount: &FilesystemMount{Device: "/foo", Format: "ext4"}}},
			out: out{err: ErrFilesystemMountAndPath},
		},
		{
			in:  in{filesystem: Filesystem{}},
			out: out{err: ErrFilesystemNoMountPath},
		},
	}

	for i, test := range tests {
		err := test.in.filesystem.Validate()
		if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
			t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
		}
	}
}
开发者ID:coreos,项目名称:fuze,代码行数:37,代码来源:filesystem_test.go


示例19: Validate

func (p Path) Validate() report.Report {
	if !filepath.IsAbs(string(p)) {
		return report.ReportFromError(ErrPathRelative, report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:6,代码来源:path.go


示例20: Validate

func (f File) Validate() report.Report {
	if f.Filesystem == "" {
		return report.ReportFromError(ErrNoFilesystem, report.EntryError)
	}
	return report.Report{}
}
开发者ID:coreos,项目名称:fuze,代码行数:6,代码来源:file.go



注:本文中的github.com/coreos/ignition/config/validate/report.ReportFromError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang context.Background函数代码示例发布时间:2022-05-23
下一篇:
Golang tspi.Context类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap