-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransparent.go
71 lines (60 loc) · 1.45 KB
/
transparent.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
67
68
69
70
71
package main
import (
"github.com/gin-gonic/gin"
"ksp.sk/transparent/candle"
"ksp.sk/transparent/config"
"ksp.sk/transparent/event"
"net/http"
"time"
)
import _ "gopkg.in/yaml.v2"
func getCandle(c *gin.Context) {
events, err := candle.Events(time.Now())
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
}
events = event.SetEventWidths(events)
var ticks []time.Time
for i := 8; i < 23; i++ {
ticks = append(ticks, time.Date(0, 0, 0, i, 0, 0, 0, time.Local))
}
c.HTML(http.StatusOK, "candle.gohtml", gin.H{
"events": events,
"ticks": ticks,
})
}
func getIndex(c *gin.Context) {
c.HTML(http.StatusOK, "index.gohtml", nil)
}
func main() {
err := config.Load()
if err != nil {
panic(err)
}
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.FuncMap["timeString"] = func(t time.Time) string {
return t.Format("15:04")
}
router.FuncMap["topForTime"] = func(t time.Time) int {
t = t.Local()
return 120*(t.Hour()-8) + t.Minute()*2
}
router.FuncMap["pxForDuration"] = func(d time.Duration) int {
return int(d.Seconds()/60) * 2
}
router.FuncMap["percentage"] = func(a, b int) float64 {
return float64(a) / float64(b) * 100
}
router.FuncMap["multiply"] = func(a float64, b int) float64 {
return a * float64(b)
}
router.LoadHTMLGlob("templates/*")
router.GET("/", getIndex)
router.GET("/candle", getCandle)
router.Static("/static", "./static")
err = router.Run()
if err != nil {
panic(err)
}
}