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-04 19:28:46 +02:00
var goods [ ] * 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-04 19:28:46 +02:00
database . Read . Find ( & goods ) . Count ( & count )
database . Read . Raw ( "SELECT avg(g.gcount) as avg FROM (select count(*) as gcount FROM good g WHERE deleted_at is NULL 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
}