Compare commits
	
		
			3 Commits
		
	
	
		
			d2a050bd8f
			...
			7de921b1b5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7de921b1b5 | |||
| 6215ecb82a | |||
| fe4d539e91 | 
							
								
								
									
										8
									
								
								entry.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								entry.go
									
									
									
									
									
								
							| @@ -39,6 +39,10 @@ func (e *Entry) checkAuthors() error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (e *Entry) AddExtension(name string, value any) { | ||||
| 	e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}) | ||||
| } | ||||
|  | ||||
| func (e *Entry) Check() error { | ||||
| 	if e.ID == nil { | ||||
| 		return errors.New("no id element of entry") | ||||
| @@ -132,7 +136,3 @@ func (e *Entry) Check() error { | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (e *Entry) AddExtension(name string, value any) { | ||||
| 	e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}) | ||||
| } | ||||
|   | ||||
							
								
								
									
										8
									
								
								feed.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								feed.go
									
									
									
									
									
								
							| @@ -25,6 +25,10 @@ type Feed struct { | ||||
| 	Entries      []*Entry            `xml:"entry,omitempty"` | ||||
| } | ||||
|  | ||||
| func (f *Feed) AddExtension(name string, value any) { | ||||
| 	f.Extensions = append(f.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}) | ||||
| } | ||||
|  | ||||
| func (f *Feed) Check() error { | ||||
| 	if f.ID == nil { | ||||
| 		return errors.New("no id element of feed") | ||||
| @@ -156,10 +160,6 @@ func (f *Feed) Standardize() { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (f *Feed) AddExtension(name string, value any) { | ||||
| 	f.Extensions = append(f.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}) | ||||
| } | ||||
|  | ||||
| func (f *Feed) ToXML(encoding string) (string, error) { | ||||
| 	xml, err := xml.MarshalIndent(f, "", "  ") | ||||
| 	if err != nil { | ||||
|   | ||||
							
								
								
									
										19
									
								
								person.go
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								person.go
									
									
									
									
									
								
							| @@ -1,8 +1,11 @@ | ||||
| package atomfeed | ||||
|  | ||||
| import ( | ||||
| 	"encoding/xml" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"net/mail" | ||||
| 	"net/url" | ||||
| ) | ||||
|  | ||||
| type Person struct { | ||||
| @@ -17,11 +20,27 @@ func NewPerson(name string) *Person { | ||||
| 	return &Person{Name: name} | ||||
| } | ||||
|  | ||||
| func (p *Person) AddExtension(name string, value any) { | ||||
| 	p.Extensions = append(p.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value}) | ||||
| } | ||||
|  | ||||
| func (p *Person) Check() error { | ||||
| 	if p.Name == "" { | ||||
| 		return errors.New("name element of person element empty") | ||||
| 	} | ||||
|  | ||||
| 	if p.URI != "" { | ||||
| 		if _, err := url.ParseRequestURI(string(p.URI)); err != nil { | ||||
| 			return fmt.Errorf("email element of person %v not correctly formatted", p.Name) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if p.Email != "" { | ||||
| 		if _, err := mail.ParseAddress(string(p.Email)); err != nil { | ||||
| 			return fmt.Errorf("email element of person %v not correctly formatted", p.Name) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if p.Extensions != nil { | ||||
| 		for i, e := range p.Extensions { | ||||
| 			if err := e.Check(); err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user