State of an API with OClib :D
This commit is contained in:
parent
c5f45e03f3
commit
4693b96130
16
tools/api.go
16
tools/api.go
@ -1,6 +1,8 @@
|
|||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,18 +26,22 @@ func (s State) String() string {
|
|||||||
|
|
||||||
type API struct{}
|
type API struct{}
|
||||||
|
|
||||||
func (a *API) GetState() State {
|
func (a *API) GetState() (State, int, error) {
|
||||||
// Check if the database is up
|
// Check if the database is up
|
||||||
err := mongo.MONGOService.TestDB(GetConfig())
|
err := mongo.MONGOService.TestDB(GetConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DB_FALLOUT
|
return DB_FALLOUT, 200, err
|
||||||
}
|
}
|
||||||
err = mongo.MONGOService.TestCollections(GetConfig(), []string{})
|
err = mongo.MONGOService.TestCollections(GetConfig(), []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return UNPROCESSABLE_ENTITY
|
return UNPROCESSABLE_ENTITY, 200, err
|
||||||
}
|
}
|
||||||
if len(UncatchedError) > 0 {
|
if len(UncatchedError) > 0 {
|
||||||
return TEAPOT
|
errStr := ""
|
||||||
|
for _, e := range UncatchedError {
|
||||||
|
errStr += e.Error() + "\n"
|
||||||
}
|
}
|
||||||
return ALIVE
|
return TEAPOT, 200, errors.New(errStr)
|
||||||
|
}
|
||||||
|
return ALIVE, 200, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user