State of an API with OClib :D

This commit is contained in:
mr 2024-08-21 11:23:07 +02:00
parent c5f45e03f3
commit 4693b96130

View File

@ -1,6 +1,8 @@
package tools
import (
"errors"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
)
@ -24,18 +26,22 @@ func (s State) String() string {
type API struct{}
func (a *API) GetState() State {
func (a *API) GetState() (State, int, error) {
// Check if the database is up
err := mongo.MONGOService.TestDB(GetConfig())
if err != nil {
return DB_FALLOUT
return DB_FALLOUT, 200, err
}
err = mongo.MONGOService.TestCollections(GetConfig(), []string{})
if err != nil {
return UNPROCESSABLE_ENTITY
return UNPROCESSABLE_ENTITY, 200, err
}
if len(UncatchedError) > 0 {
return TEAPOT
errStr := ""
for _, e := range UncatchedError {
errStr += e.Error() + "\n"
}
return TEAPOT, 200, errors.New(errStr)
}
return ALIVE
return ALIVE, 200, nil
}