version setup

This commit is contained in:
mr 2024-08-21 11:45:36 +02:00
parent da549d7f66
commit e9dc2ba043
2 changed files with 28 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package controllers package controllers
import ( import (
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
) )
@ -17,3 +18,25 @@ func (c *VersionController) GetAll() {
c.Data["json"] = map[string]string{"version": "1"} c.Data["json"] = map[string]string{"version": "1"}
c.ServeJSON() c.ServeJSON()
} }
// @Title Status
// @Description get status
// @Success 200
// @router /status [get]
func (c *VersionController) Status() {
api := tools.API{}
state, code, err := api.GetState()
if state == tools.ALIVE {
state, _, err = api.CheckRemoteAPIs([]string{})
}
c.Data["json"] = map[string]interface{}{
"data": map[string]interface{}{
"state": state.String(),
"code": state,
},
"error": err.Error(),
"code": code,
}
c.ServeJSON()
}

17
main.go
View File

@ -4,37 +4,30 @@ import (
_ "oc-catalog/routers" _ "oc-catalog/routers"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"github.com/goraz/onion" "github.com/goraz/onion"
) )
const defaultConfigFile = "/etc/oc/catalog.json" const defaultConfigFile = "/etc/oc/catalog.json"
const localConfigFile = "./docker_catalog.json"
func main() { func main() {
configFile := "" configFile := ""
var o *onion.Onion var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCCATALOG_") l3 := onion.NewEnvLayerPrefix("_", "OCCATALOG_")
l1, err := onion.NewFileLayer(localConfigFile, nil)
if err == nil {
configFile = localConfigFile
}
l2, err := onion.NewFileLayer(defaultConfigFile, nil) l2, err := onion.NewFileLayer(defaultConfigFile, nil)
if err == nil { if err == nil {
configFile = defaultConfigFile configFile = defaultConfigFile
} }
if configFile == "" { if configFile == "" || l2 == nil {
o = onion.New(l3) o = onion.New(l3)
} else if l1 == nil && l2 == nil { } else {
o = onion.New(l1, l2, l3)
} else if l1 == nil {
o = onion.New(l2, l3) o = onion.New(l2, l3)
} else if l2 == nil {
o = onion.New(l1, l3)
} }
oclib.SetConfig( tools.SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
"",
) )
oclib.Init("oc-catalog") oclib.Init("oc-catalog")
// Normal beego init // Normal beego init