-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
40 lines (34 loc) · 754 Bytes
/
parser.go
File metadata and controls
40 lines (34 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package presskit
import (
"encoding/xml"
)
// Parser parses all data files
type Parser interface {
Extension() string
Company([]byte) (*company, error)
Game([]byte) (*game, error)
}
// XMLParser parses the data from xml files
type XMLParser struct{}
// Extension returns the file extension the parser uses
func (p XMLParser) Extension() string {
return "xml"
}
// Company parses the company data
func (p XMLParser) Company(data []byte) (*company, error) {
var c company
err := xml.Unmarshal(data, &c)
if err != nil {
return nil, err
}
return &c, nil
}
// Game parses data of a game
func (p XMLParser) Game(data []byte) (*game, error) {
var g game
err := xml.Unmarshal(data, &g)
if err != nil {
return nil, err
}
return &g, nil
}