-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.go
More file actions
38 lines (32 loc) · 934 Bytes
/
templates.go
File metadata and controls
38 lines (32 loc) · 934 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
package timelineTracing
import (
"bytes"
"embed"
"encoding/json"
"fmt"
"html/template"
)
//go:embed templateDatadogTraceLink.html
//go:embed template.html
//go:embed templateOpenWithPerfetto.html
var embeddedData embed.FS
type templateName string
const (
templateDatadogHtml templateName = "templateDatadogTraceLink.html"
templateHtml templateName = "template.html"
templateTraceHtml templateName = "templateOpenWithPerfetto.html"
)
func loadTemplate(templateName templateName) (*template.Template, error) {
t, err := template.ParseFS(embeddedData, string(templateName))
if err != nil {
return nil, fmt.Errorf("failed to parse the template file %q: %w", templateName, err)
}
return t, nil
}
func marshalWithoutEscapingHTML(t interface{}) ([]byte, error) {
buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
err := encoder.Encode(t)
return buffer.Bytes(), err
}