This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmarshal.go
52 lines (47 loc) · 1.49 KB
/
marshal.go
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
41
42
43
44
45
46
47
48
49
50
51
52
package xmp
import (
"encoding/json"
"time"
)
// POD is a high-level interpretation of the Project Open Data
// data.json spec:
// https://project-open-data.cio.gov/v1.1/schema/
type POD struct {
Title string `json:"title"`
Description string `json:"description"`
Keyword []string `json:"keyword"`
Created *time.Time `json:"created"`
Modified *time.Time `json:"modified"`
Publisher string `json:"publisher"`
ContactPoint string `json:"contactPoint"`
Identifier string `json:"identifier"`
AccessLevel string `json:"accessLevel"`
BureauCode string `json:"bureauCode"`
ProgramCode string `json:"programCode"`
License string `json:"license"`
Rights string `json:"rights"`
}
func (p *POD) AsObject() (map[string]interface{}, error) {
data, err := json.Marshal(p)
if err != nil {
return nil, err
}
obj := map[string]interface{}{}
err = json.Unmarshal(data, &obj)
return obj, err
}
// AsPOD turns an XMPPacket into a Project Open Data struct
func (p *XMPPacket) AsPOD() *POD {
return &POD{
Title: p.RDF.Description.Title.Default(),
Description: p.RDF.Description.Description.Default(),
Keyword: p.RDF.Description.Subject.Default(),
Modified: p.RDF.Description.ModifyDate,
Publisher: p.RDF.Description.Creator.String(),
// TODO
}
}
// MarshalPODJSON renders XMP metadata as Project Open Data Metadata
func (p *XMPPacket) MarshalPODJSON() ([]byte, error) {
return json.Marshal(p.AsPOD())
}