beego.go
1.2 KB
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 beego
import (
"os"
"path/filepath"
"strconv"
"time"
"github.com/beego/beego/v2/server/web"
"github.com/linmadan/egglib-go/web/beego/filters"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/routers"
)
func init() {
web.BConfig.AppName = "performance"
web.BConfig.CopyRequestBody = true
web.BConfig.RunMode = "dev"
web.BConfig.Listen.HTTPPort = 8082
web.BConfig.Listen.EnableAdmin = false
// web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
if os.Getenv("RUN_MODE") != "" {
web.BConfig.RunMode = os.Getenv("RUN_MODE")
}
if os.Getenv("HTTP_PORT") != "" {
portStr := os.Getenv("HTTP_PORT")
if port, err := strconv.Atoi(portStr); err == nil {
web.BConfig.Listen.HTTPPort = port
}
}
//增加https
path, _ := filepath.Abs(".")
web.BConfig.Listen.EnableHTTPS = false
if os.Getenv("ENABLE_HTTPS") == "true" {
web.BConfig.Listen.EnableHTTPS = true
}
web.BConfig.Listen.HTTPSPort = 443
web.BConfig.Listen.HTTPSKeyFile = path + "/key/fjmaimaimai.com.key"
web.BConfig.Listen.HTTPSCertFile = path + "/key/fjmaimaimai.com_bundle.crt"
// 默认时区设置
timeLocal, _ := time.LoadLocation("Asia/Chongqing")
time.Local = timeLocal
web.InsertFilter("/*", web.BeforeRouter, filters.AllowCors())
}