2017-03-25 16:09:17 +01:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2017-03-30 18:43:18 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
2017-03-30 15:36:04 +02:00
|
|
|
lib "github.com/genofire/hs_master-kss-monolith/lib/http"
|
|
|
|
logger "github.com/genofire/hs_master-kss-monolith/lib/log"
|
2017-03-30 18:43:18 +02:00
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
2017-03-25 16:09:17 +01:00
|
|
|
)
|
|
|
|
|
2017-03-30 18:43:18 +02:00
|
|
|
func status(w http.ResponseWriter, r *http.Request) {
|
2017-03-30 15:36:04 +02:00
|
|
|
log := logger.HTTP(r)
|
2017-04-03 14:59:43 +02:00
|
|
|
var good []*models.Good
|
2017-03-30 18:43:18 +02:00
|
|
|
var count int64
|
2017-04-04 07:37:39 +02:00
|
|
|
var avg float64
|
2017-04-03 14:59:43 +02:00
|
|
|
database.Read.Find(&good).Count(&count) //.Avg(&avg)
|
2017-04-04 07:37:39 +02:00
|
|
|
database.Read.Raw("SELECT avg(g.gcount) as avg FROM (select count(*) as gcount FROM good g GROUP BY g.product_id) g").Row().Scan(&avg)
|
2017-04-03 14:59:43 +02:00
|
|
|
lib.Write(w, map[string]interface{}{
|
|
|
|
"status": "running",
|
2017-04-04 07:37:39 +02:00
|
|
|
"database": map[string]interface{}{
|
|
|
|
"read": database.Read.DB().Ping() == nil,
|
|
|
|
"write": database.Write.DB().Ping() == nil,
|
|
|
|
},
|
2017-04-03 14:59:43 +02:00
|
|
|
"good": map[string]interface{}{
|
|
|
|
"count": count,
|
|
|
|
"avg": avg,
|
|
|
|
},
|
|
|
|
})
|
2017-03-30 18:43:18 +02:00
|
|
|
log.Info("done")
|
2017-03-25 16:09:17 +01:00
|
|
|
}
|