/
template.go
44 lines (38 loc) 路 858 Bytes
/
template.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
package util
import (
"github.com/gin-gonic/gin"
"github.com/muety/kitsquid/app/common/errors"
"github.com/muety/kitsquid/app/config"
)
/*
MakeError creates a new error in Gin
*/
func MakeError(c *gin.Context, tpl string, status int, error errors.KitSquidError, args *gin.H) {
tplCtx := c.MustGet(config.TemplateContextKey)
tplCtx.(*TplCtx).Errors = append(tplCtx.(*TplCtx).Errors, error.Error())
h := gin.H{
"tplCtx": tplCtx,
}
if args != nil {
for k, v := range *args {
h[k] = v
}
}
c.HTML(status, tpl, h)
}
/*
TplCtx represents a collection of all properties to be attached to all templates
*/
type TplCtx struct {
User interface{}
Url string
Path string
Constants struct {
FacultyIndex int
VvzBaseUrl string
}
Alerts []string
Errors []string
SemesterKeys []string
Version string
}