-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
69 lines (62 loc) · 1.85 KB
/
Copy pathmain.go
File metadata and controls
69 lines (62 loc) · 1.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/plugins/cors"
_ "github.com/lib/pq"
_ "github.com/udistrital/oikos_api/routers"
apistatus "github.com/udistrital/utils_oas/apiStatusLib"
"github.com/udistrital/utils_oas/auditoria"
"github.com/udistrital/utils_oas/customerrorv2"
"github.com/udistrital/utils_oas/database"
"github.com/udistrital/utils_oas/security"
"github.com/udistrital/utils_oas/xray"
)
func dev() {
if beego.BConfig.RunMode == "dev" {
orm.Debug = true
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
}
func main() {
conn, err := database.BuildPostgresConnectionString()
if err != nil {
logs.Error("error consultando la cadena de conexión: %v", err)
return
}
err = orm.RegisterDataBase("default", "postgres", conn)
if err != nil {
logs.Error("error al conectarse a la base de datos: %v", err)
return
}
allowedOrigins := []string{"*.udistrital.edu.co"}
if beego.BConfig.RunMode == beego.DEV {
allowedOrigins = []string{"*"}
orm.Debug = true
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
}
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"DELETE", "GET", "OPTIONS", "PATCH", "POST", "PUT"},
AllowHeaders: []string{
"Accept",
"Authorization",
"Content-Type",
"User-Agent",
"X-Amzn-Trace-Id"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
err = xray.InitXRay()
if err != nil {
logs.Error("error configurando AWS XRay: %v", err)
}
apistatus.Init()
auditoria.InitMiddleware()
beego.ErrorController(&customerrorv2.CustomErrorController{})
security.SetSecurityHeaders()
beego.Run()
}