2023-08-26 22:04:56 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-26 10:59:21 +02:00
|
|
|
"oc-search/controllers"
|
2023-10-25 11:46:14 +02:00
|
|
|
"oc-search/models"
|
2023-08-26 22:04:56 +02:00
|
|
|
_ "oc-search/routers"
|
|
|
|
_ "oc-search/views"
|
|
|
|
|
2023-10-25 11:46:14 +02:00
|
|
|
"github.com/beego/beego/logs"
|
2023-08-26 22:04:56 +02:00
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
2023-10-25 11:46:14 +02:00
|
|
|
"github.com/goraz/onion"
|
2023-08-26 22:04:56 +02:00
|
|
|
)
|
|
|
|
|
2023-10-25 11:46:14 +02:00
|
|
|
const defaultConfigFile = "/etc/oc/search.json"
|
|
|
|
const localConfigFile = "./search.json"
|
|
|
|
|
2023-08-26 22:04:56 +02:00
|
|
|
func main() {
|
2023-10-26 10:59:21 +02:00
|
|
|
|
|
|
|
loadConfig()
|
|
|
|
controllers.CreateOCCatalogAPI()
|
|
|
|
|
|
|
|
beego.BConfig.WebConfig.Session.SessionOn = true
|
|
|
|
beego.SetStaticPath("/favicon.ico", "/static/favicon.ico")
|
|
|
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
|
|
|
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
|
|
|
|
|
|
|
beego.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialising the config in the init so that the oc-catalog API receives it
|
|
|
|
|
|
|
|
func loadConfig(){
|
2023-10-25 11:46:14 +02:00
|
|
|
log := logs.NewLogger(10000)
|
|
|
|
log.SetLogger("console")
|
|
|
|
|
|
|
|
configFile := ""
|
|
|
|
var o *onion.Onion
|
|
|
|
l3 := onion.NewEnvLayerPrefix("_", "OCDISCOVERY_")
|
|
|
|
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
|
|
|
if err == nil {
|
|
|
|
logs.Info("Config file found : " + defaultConfigFile)
|
|
|
|
configFile = defaultConfigFile
|
|
|
|
}
|
|
|
|
l1, err := onion.NewFileLayer(localConfigFile, nil)
|
|
|
|
if err == nil {
|
|
|
|
logs.Info("Local config file found " + localConfigFile + ", overriding default file")
|
|
|
|
configFile = localConfigFile
|
|
|
|
}
|
|
|
|
if configFile == "" {
|
|
|
|
logs.Info("No config file found, using env")
|
|
|
|
o = onion.New(l3)
|
|
|
|
} else if l1 == nil && l2 == nil {
|
|
|
|
o = onion.New(l1, l2, l3)
|
|
|
|
} else if l1 == nil {
|
|
|
|
o = onion.New(l2, l3)
|
|
|
|
} else if l2 == nil {
|
|
|
|
o = onion.New(l1, l3)
|
|
|
|
}
|
|
|
|
|
|
|
|
models.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "localhost:49618")
|
2023-10-26 10:59:21 +02:00
|
|
|
logs.Info("Value for oc-catalog url : " + models.GetConfig().OcCatalogUrl)
|
2023-08-26 22:04:56 +02:00
|
|
|
}
|