...
1 package model
2
3 import (
4 "html"
5 "html/template"
6 "log"
7 "regexp"
8 "time"
9 )
10
11 type Log struct {
12 ID int
13 Account *Account
14 Board *Board
15 Timestamp int64
16 Message string
17 Changes string
18 }
19
20 func (l *Log) TimestampDate() string {
21 return time.Unix(l.Timestamp, 0).Format("2006-01-02 15:04:05 MST")
22 }
23
24 func (l *Log) formatLabel(message string) template.HTML {
25 if len(message) == 0 {
26 return ""
27 }
28 message = html.EscapeString(message)
29 rgxp, err := regexp.Compile(`>>/([0-9A-Za-z_-]+)/([0-9]+)`)
30 if err != nil {
31 log.Fatal(err)
32 }
33 return template.HTML(rgxp.ReplaceAllString(message, `<a href="/sriracha/$1/$2">$1 #$2</a>`))
34 }
35
36 func (l *Log) MessageLabel() template.HTML {
37 return l.formatLabel(l.Message)
38 }
39
40 func (l *Log) InfoLabel() template.HTML {
41 return l.formatLabel(l.Changes)
42 }
43
View as plain text