package tools import ( "cloud.o-forge.io/core/oc-lib/dbs/mongo" ) var UncatchedError = []error{} type State int const ( ALIVE State = iota REDUCED_SERVICE UNPROCESSABLE_ENTITY DB_FALLOUT TEAPOT DEAD ) func (s State) String() string { return [...]string{"alive", "reduced service", "unprocessable entity", "database fallout", "some things boils in here, i'm probably a teapot", "dead"}[s] } type API struct{} func (a *API) GetState() State { // Check if the database is up err := mongo.MONGOService.TestDB(GetConfig()) if err != nil { return DB_FALLOUT } err = mongo.MONGOService.TestCollections(GetConfig(), []string{}) if err != nil { return UNPROCESSABLE_ENTITY } if len(UncatchedError) > 0 { return TEAPOT } return ALIVE }