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


Golang utils.NewError函數代碼示例

本文整理匯總了Golang中github.com/apognu/xml/utils.NewError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewError函數的具體用法?Golang NewError怎麽用?Golang NewError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestEnclosureBasic

func TestEnclosureBasic(t *testing.T) {

	var testdata = []testEnclosure{
		{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />`,
			nil,
			NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "12216320", "audio/mpeg"),
		},
		{`<enclosure length="12216320" type="audio/mpeg" />`,
			xmlutils.NewError(MissingAttribute, ""),
			NewTestEnclosure("", "12216320", "audio/mpeg"),
		},
		{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" type="audio/mpeg" />`,
			xmlutils.NewError(MissingAttribute, ""),
			NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "", "audio/mpeg"),
		},
		{`<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" />`,
			xmlutils.NewError(MissingAttribute, ""),
			NewTestEnclosure("http://www.scripting.com/mp3s/weatherReportSuite.mp3", "12216320", ""),
		},
	}

	nbErrors := 0
	len := len(testdata)
	for _, testenclosure := range testdata {
		testcase := _TestEnclosureToTestVisitor(testenclosure)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:34,代碼來源:enclosure_test.go

示例2: validateLinks

func (e *Entry) validateLinks(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)
	hasAlternateRel := false

	for _, link := range e.Links {
		if link.Rel.Value == "alternate" {
			hasAlternateRel = true
			s := link.Type.Value + link.HrefLang.Value
			unique := true

			for _, comb := range combinations {
				if s == comb {
					err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
					unique = false
				}
			}

			if unique {
				combinations = append(combinations, s)
			}
		}
	}

	if e.Occurences.Count("content") == 0 && !hasAlternateRel {
		err.NewError(xmlutils.NewError(NoContentOrAlternateLink, "Entry should have either a Content element or a Link with alternate type"))
	}
}
開發者ID:apognu,項目名稱:xml,代碼行數:27,代碼來源:entry.go

示例3: TestDateBasic

func TestDateBasic(t *testing.T) {

	var testdata = []testDate{
		{`<updated>Tue, 20 Sep 2010 16:02:50 GMT</updated>`,
			nil,
			NewTestDate("Tue, 20 Sep 2010 16:02:50 GMT"),
		},
		{`<updated>Tue, 20 Sep 2010 16:02:50</updated>`,
			xmlutils.NewError(DateFormat, ""),
			NewTestDate("0"),
		},
		{`<updated>2003-12-13T18:30:02.25</updated>`,
			xmlutils.NewError(DateFormat, ""),
			NewTestDate("0"),
		},
	}
	nbErrors := 0
	len := len(testdata)
	for _, testdate := range testdata {
		testcase := testDateToTestVisitor(testdate)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:29,代碼來源:date_test.go

示例4: TestIdBasic

func TestIdBasic(t *testing.T) {

	var testdata = []testId{
		{`<id xml:lang="en-us" xml:base="http://yo.com">https://www.yo.com</id>`,
			nil,
			IdWithBaseLang(NewTestId("https://www.yo.com"), "en-us", "http://yo.com"),
		},
		{`<id>https://www.yo.com</id>`,
			nil,
			NewTestId("https://www.yo.com"),
		},
		{`<id>https://www.%yo.com</id>`,
			xmlutils.NewError(IriNotAbsolute, ""),
			NewTestId("https://www.%yo.com"),
		},
		{`<id>
      https://www.%yo.com
     </id>`,
			xmlutils.NewError(IriNotAbsolute, ""),
			NewTestId("https://www.%yo.com"),
		},
	}
	nbErrors := 0
	len := len(testdata)
	for _, testid := range testdata {
		testcase := testIdToTestVisitor(testid)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:35,代碼來源:id_test.go

示例5: ProcessEndElement

func (i *InlineXHTMLContent) ProcessEndElement(el xml.EndElement) (xmlutils.Visitor, xmlutils.ParserError) {
	level := i.depth.Up()
	if level == xmlutils.RootLevel {

		if err := i.EncodeXHTMLToken(el); err != nil {
			return i, xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML")
		}

		if err := i.flush(); err != nil {
			return i, err
		}

		i.completed = true

		return i, nil
	}

	if level == xmlutils.ParentLevel {
		if err := i.flush(); err != nil {
			return i.Parent, err
		}

		if i.Parent != nil {
			return i.Parent.ProcessEndElement(el)
		}
		return nil, nil
	}

	if err := i.EncodeXHTMLToken(el); err != nil {
		return i, xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML")
	}

	return i, nil
}
開發者ID:apognu,項目名稱:xml,代碼行數:34,代碼來源:inlineXHTMLcontent.go

示例6: validateLinks

func (f *Feed) validateLinks(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)
	hasSelf := false

	for _, link := range f.Links {
		if link.Rel.Value == "alternate" {
			s := link.Type.Value + link.HrefLang.Value
			unique := true

			for _, comb := range combinations {
				if s == comb {
					err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
					unique = false
				}
			}

			if unique {
				combinations = append(combinations, s)
			}
		} else if link.Rel.Value == "self" {
			hasSelf = true
		}
	}

	if !hasSelf {
		err.NewError(xmlutils.NewError(MissingSelfLink, "Feed must have a link with rel attribute set to 'self'"))
	}
}
開發者ID:apognu,項目名稱:xml,代碼行數:28,代碼來源:feed.go

示例7: TestGeneratorBasic

func TestGeneratorBasic(t *testing.T) {

	var testdata = []testGenerator{
		{`<generator uri="http://there.com" version="4.0" xml:lang="en-us" xml:base="http://yo.com">my generator</generator>`,
			nil,
			GeneratorWithBaseLang(NewTestGenerator("4.0", "http://there.com", "my generator"), "en-us", "http://yo.com"),
		},
		{`<generator uri="http://there.com" version="4.0">my generator</generator>`,
			nil,
			NewTestGenerator("4.0", "http://there.com", "my generator"),
		},
		{`<generator uri="http://there.com" version="4.0"><name>CHILD</name></generator>`,
			xmlutils.NewError(LeafElementHasChild, ""),
			NewTestGenerator("4.0", "http://there.com", "CHILD"),
		},
		{`<generator uri="http://%there.com" version="4.0">my generator</generator>`,
			xmlutils.NewError(IriNotValid, ""),
			NewTestGenerator("4.0", "http://%there.com", "my generator"),
		},
	}
	nbErrors := 0
	len := len(testdata)
	for _, testgenerator := range testdata {
		testcase := testGeneratorToTestVisitor(testgenerator)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:33,代碼來源:generator_test.go

示例8: Validate

func (u *Updated) Validate() xmlutils.ParserError {
	errAgg := utils.NewErrorAggregator()
	link, ok := u.Parent.(*atom.Link)
	if !ok {
		errAgg.NewError(xmlutils.NewError(NotInLinkElement, "updated attr should be placed in link element"))

	} else {
		if link.Rel.String() != "replies" {
			errAgg.NewError(xmlutils.NewError(LinkNotReplies, "link element should avec a 'replies' rel for this extension"))
		}
	}

	return errAgg.ErrorObject()
}
開發者ID:apognu,項目名稱:xml,代碼行數:14,代碼來源:link.go

示例9: relIsIANA

func relIsIANA(name, s string) xmlutils.ParserError {
	if s == "alternate" || s == "related" || s == "self" || s == "enclosure" || s == "via" {
		return nil
	}

	return xmlutils.NewError(RelNotValid, fmt.Sprintf("rel is not valid: %s", s))
}
開發者ID:apognu,項目名稱:xml,代碼行數:7,代碼來源:validator.go

示例10: contentTypeIsValid

func contentTypeIsValid(name, s string) xmlutils.ParserError {
	if s == "text" || s == "html" || s == "xhtml" {
		return xmlutils.NewError(ContentTypeIsNotValid, "type not valid")
	}

	return nil
}
開發者ID:apognu,項目名稱:xml,代碼行數:7,代碼來源:validator.go

示例11: ProcessStartElement

func (i *InlineOtherContent) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	err := utils.NewErrorAggregator()

	if i.depth.IsRoot() {
		for _, attr := range el.Attr {
			switch attr.Name.Local {
			case "type":
				i.Type.Value = attr.Value
				i.Type.IncOccurence()

			}
		}

	} else {
		if error := i.Encoder.EncodeToken(el); error != nil {
			err.NewError(xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML"))
		}
		if i.depth.Level > 0 {
			i.hasChild = true
		}
	}

	i.depth.Down()

	return i, nil
}
開發者ID:apognu,項目名稱:xml,代碼行數:26,代碼來源:inlineothercontent.go

示例12: TestLogoBasic

func TestLogoBasic(t *testing.T) {

	var testdata = []testLogo{
		{`<logo xml:lang="en-us" xml:base="http://yo.com">https://www.yo.com</logo>`,
			nil,
			LogoWithBaseLang(NewTestLogo("https://www.yo.com"), "en-us", "http://yo.com"),
		},
		{`<logo>https://www.yo.com</logo>`,
			nil,
			NewTestLogo("https://www.yo.com"),
		},
		{`<logo>https://www.%yo.com</logo>`,
			xmlutils.NewError(IriNotValid, ""),
			NewTestLogo("https://www.%yo.com"),
		},
	}
	nbErrors := 0
	len := len(testdata)
	for _, testlogo := range testdata {
		testcase := testLogoToTestVisitor(testlogo)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:29,代碼來源:logo_test.go

示例13: ProcessStartElement

func (g *Generator) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	if g.depth.IsRoot() {
		g.reset()
		for _, attr := range el.Attr {
			switch attr.Name.Space {
			case xmlutils.XML_NS:
				g.ProcessAttr(attr)

			case "":
				switch attr.Name.Local {
				case "uri":
					g.Uri.Value = attr.Value
					g.Uri.IncOccurence()

				case "version":
					g.Version.Value = attr.Value
					g.Version.IncOccurence()
				}
			default:
				g.Extension.ProcessAttr(attr, g)
			}
		}
	}

	if g.depth.Down() == xmlutils.MaxDepthReached {
		return g, xmlutils.NewError(LeafElementHasChild, "'generator' shoud not have childs")

	}

	return g, nil
}
開發者ID:apognu,項目名稱:xml,代碼行數:31,代碼來源:generator.go

示例14: TestSourceBasic

func TestSourceBasic(t *testing.T) {

	var testdata = []testSource{
		{`<source>Tomalak's Realm</source>`,
			xmlutils.NewError(MissingAttribute, ""),
			NewTestSource("", "Tomalak's Realm"),
		},
		{`<source url="http://www.tomaltak.org/links2.xml">Tomalak's Realm</source>`,
			nil,
			NewTestSource("http://www.tomaltak.org/links2.xml", "Tomalak's Realm"),
		},
	}

	nbErrors := 0
	len := len(testdata)
	for _, testsource := range testdata {
		testcase := _TestSourceToTestVisitor(testsource)

		if err := testcase.CheckTestCase(); err != nil {
			t.Errorf("FAIL\n%s\nXML:\n %s\n", err, testcase.XML)
			nbErrors++
		}
	}

	t.Logf("PASS RATIO = %v/%v\n", len-nbErrors, len)
}
開發者ID:apognu,項目名稱:xml,代碼行數:26,代碼來源:source_test.go

示例15: flush

func (i *InlineXHTMLContent) flush() xmlutils.ParserError {
	err := i.Encoder.Flush()

	if err != nil {
		return xmlutils.NewError(CannotFlush, "cannot flush XHTML")
	}
	return nil
}
開發者ID:apognu,項目名稱:xml,代碼行數:8,代碼來源:inlineXHTMLcontent.go


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