version setup
This commit is contained in:
parent
da549d7f66
commit
e9dc2ba043
@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
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.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
17
main.go
@ -4,37 +4,30 @@ import (
|
||||
_ "oc-catalog/routers"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/goraz/onion"
|
||||
)
|
||||
|
||||
const defaultConfigFile = "/etc/oc/catalog.json"
|
||||
const localConfigFile = "./docker_catalog.json"
|
||||
|
||||
func main() {
|
||||
configFile := ""
|
||||
var o *onion.Onion
|
||||
l3 := onion.NewEnvLayerPrefix("_", "OCCATALOG_")
|
||||
l1, err := onion.NewFileLayer(localConfigFile, nil)
|
||||
if err == nil {
|
||||
configFile = localConfigFile
|
||||
}
|
||||
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
||||
if err == nil {
|
||||
configFile = defaultConfigFile
|
||||
}
|
||||
if configFile == "" {
|
||||
if configFile == "" || l2 == nil {
|
||||
o = onion.New(l3)
|
||||
} else if l1 == nil && l2 == nil {
|
||||
o = onion.New(l1, l2, l3)
|
||||
} else if l1 == nil {
|
||||
} else {
|
||||
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_DATABASE", "DC_myDC"),
|
||||
"",
|
||||
)
|
||||
oclib.Init("oc-catalog")
|
||||
// Normal beego init
|
||||
|
Loading…
Reference in New Issue
Block a user