-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (45 loc) · 1.46 KB
/
main.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
/*
* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved.
* ha-api licensed under the Mulan Permissive Software License, Version 2.
* See LICENSE file for more details.
* Author: yangzhao_kl <[email protected]>
* Date: Tue Jan 5 09:33:00 2021 +0800
*/
package main
import (
"net/http"
_ "gitee.com/openeuler/ha-api/routers"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"github.com/chai2010/gettext-go"
"gitee.com/openeuler/ha-api/utils"
)
func pageNotFoundHandler(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte("page not found"))
}
func detectUserLanguage() string {
// Todo: check user language preferences, check environment variables, user profiles, or HTTP request headers
return "zh_CN"
}
func init() {
gettext.BindLocale(gettext.New("ha-api", "locale"))
switch language := detectUserLanguage(); language {
case "zh_CN":
gettext.SetLanguage("zh_CN")
default:
gettext.SetLanguage("zh_CN") // default chinese
}
}
func main() {
logs.SetLogger("console")
logs.SetLevel(logs.LevelNotice)
web.BConfig.CopyRequestBody = true
web.SetStaticPath("/static", "views/static")
// web.SetStaticPath("/4.12.13", "views/static/4.12.13")
// web.SetStaticPath("/static", "views/static/static")
web.BConfig.WebConfig.Session.SessionOn = true
web.BConfig.WebConfig.Session.SessionGCMaxLifetime = 300
web.ErrorHandler("404", pageNotFoundHandler)
port, _ := utils.ReadPortFromConfig()
web.Run(":" + port)
}