/
base.go
46 lines (39 loc) · 883 Bytes
/
base.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
package rbac
import (
"github.com/astaxie/beego"
"github.com/beego/i18n"
)
// 基础控制器
type baseController struct {
beego.Controller
i18n.Locale
}
type Tree struct {
Id int64 `json:"id"`
GroupId int64 `json:"-"`
Text string `json:"text"`
IconCls string `json:"iconCls"`
Checked string `json:"checked"`
State string `json:"state"`
Children []Tree `json:"children"`
Attributes Attributes `json:"attributes"`
}
type Attributes struct {
Url string `json:"url"`
Price int64 `json:"price"`
}
// 通过浏览器获取语言
func (this *baseController) Prepare() {
this.Lang = ""
al := this.Ctx.Request.Header.Get("Accept-Language")
if len(al) > 4 {
al = al[:5]
if i18n.IsExist(al) {
this.Lang = al
}
}
if len(this.Lang) == 0 {
this.Lang = "zh-CN"
}
this.Data["Lang"] = this.Lang
}