-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_record.go
More file actions
72 lines (62 loc) · 1.5 KB
/
template_record.go
File metadata and controls
72 lines (62 loc) · 1.5 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package easclient
import (
"bytes"
"text/template"
)
const recordTemplateStr = `<?xml version="1.0"?>
<records xmlns="http://namespace.otris.de/2010/09/archive/recordExtern">
<record>
{{- if .Title}}
<title>{{.Title}}</title>
{{end}}
{{- range $key, $value := .Fields}}
<field name="{{$key}}">{{$value}}</field>{{end}}{{range $key, $value := .Attachments}}
<attachment>
<name>{{$value.Name}}</name>
<path>{{$value.Path}}</path>
{{- if $value.Size}}
<size>{{$value.Size}}</size>
{{- end}}
{{- if $value.Register}}
<register>{{$value.Register}}</register>
{{- end}}
{{- if $value.Author}}
<author>{{$value.Author}}</author>
{{- end}}
</attachment>
{{- end}}
</record>
</records>
`
var recordTemplate *template.Template
func init() {
t, err := template.New("putRecord").Parse(recordTemplateStr)
if err != nil {
panic(err)
}
recordTemplate = t
}
type RecordRequest struct {
Title string
Fields map[string]string
Attachments []*RecordRequestAttachment
}
// RecordRequestAttachment is used in a RecordRequest to specify
// spooled attachments to be added to the record.
//
// The EAS expects at least Name and Path to be set.
type RecordRequestAttachment struct {
Name string
Path string
Size uint64
Register string
Author string
}
func renderRecordTemplate(request *RecordRequest) (string, error) {
buf := new(bytes.Buffer)
err := recordTemplate.Execute(buf, request)
if err != nil {
return "", err
}
return buf.String(), nil
}