forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.go
40 lines (32 loc) · 1.05 KB
/
page.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
package page
import (
"bytes"
"github.com/chenhg5/go-admin/context"
"github.com/chenhg5/go-admin/modules/auth"
"github.com/chenhg5/go-admin/modules/config"
"github.com/chenhg5/go-admin/modules/menu"
"github.com/chenhg5/go-admin/template"
"github.com/chenhg5/go-admin/template/types"
)
// SetPageContent set and return the panel of page content.
func SetPageContent(ctx *context.Context, c func() types.Panel) {
user := ctx.UserValue["user"].(auth.User)
panel := c()
globalConfig := config.Get()
tmpl, tmplName := template.Get(globalConfig.THEME).GetTemplate(ctx.Request.Header.Get("X-PJAX") == "true")
ctx.Response.Header.Add("Content-Type", "text/html; charset=utf-8")
buf := new(bytes.Buffer)
tmpl.ExecuteTemplate(buf, tmplName, types.Page{
User: user,
Menu: menu.GetGlobalMenu(user),
System: types.SystemInfo{
"0.0.1",
},
Panel: panel,
AssertRootUrl: "/" + globalConfig.PREFIX,
Title: globalConfig.TITLE,
Logo: globalConfig.LOGO,
MiniLogo: globalConfig.MINILOGO,
})
ctx.WriteString(buf.String())
}