-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportfake.go
66 lines (53 loc) · 1.21 KB
/
reportfake.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"html/template"
"strings"
"github.com/gin-gonic/gin"
)
type FakeReportProvider struct {
Name string
Template string
}
func newFakeReportProvider() *FakeReportProvider {
p := &FakeReportProvider{}
p.Name = "fake"
p.Template = "fake.tmpl"
return p
}
func (p *FakeReportProvider) GetName() string {
return p.Name
}
func (p *FakeReportProvider) GetTemplate() string {
return p.Template
}
func (p *FakeReportProvider) GetPayload() gin.H {
data := []FakeDataPoint{
{date: "2019-10-10", data: 200},
{date: "2019-10-11", data: 560},
{date: "2019-10-12", data: 750},
{date: "2019-10-13", data: 580},
{date: "2019-10-14", data: 250},
{date: "2019-10-15", data: 300},
{date: "2019-10-16", data: 450},
{date: "2019-10-17", data: 300},
{date: "2019-10-18", data: 100},
}
// Convert data to JS array
var sb strings.Builder
sb.WriteString("[")
for _, point := range data {
sb.WriteString(fmt.Sprintf("['%s',%d],", template.JSEscapeString(point.date), point.data))
}
sb.WriteString("]")
dataStr := sb.String()
// Construct payload
return gin.H{
"Title": "fake report",
"Data": template.JS(dataStr),
}
}
type FakeDataPoint struct {
date string
data int
}