mirror of https://github.com/statping/statping
another patch for API
parent
e5785f0ea8
commit
b70857adb8
|
@ -47,7 +47,7 @@ func Services() []types.ServiceInterface {
|
|||
|
||||
// SelectService returns a *core.Service from in memory
|
||||
func SelectService(id int64) *Service {
|
||||
for _, s := range CoreApp.Services {
|
||||
for _, s := range Services() {
|
||||
if s.Select().Id == id {
|
||||
return s.(*Service)
|
||||
}
|
||||
|
@ -55,6 +55,16 @@ func SelectService(id int64) *Service {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SelectServicer returns a types.ServiceInterface from in memory
|
||||
func SelectServicer(id int64) types.ServiceInterface {
|
||||
for _, s := range Services() {
|
||||
if s.Select().Id == id {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckinProcess runs the checkin routine for each checkin attached to service
|
||||
func (s *Service) CheckinProcess() {
|
||||
checkins := s.Checkins()
|
||||
|
@ -78,20 +88,6 @@ func (s *Service) LimitedCheckins() []*Checkin {
|
|||
return checkin
|
||||
}
|
||||
|
||||
func SelectServices() []*Service {
|
||||
var services []*Service
|
||||
servicesDB().Find(&services).Order("order_id desc")
|
||||
for _, service := range services {
|
||||
failures := service.LimitedFailures(limitedFailures)
|
||||
service.Failures = nil
|
||||
for _, fail := range failures {
|
||||
utils.Log(1, fail)
|
||||
service.Failures = append(service.Failures, fail.Select())
|
||||
}
|
||||
}
|
||||
return services
|
||||
}
|
||||
|
||||
// SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
|
||||
func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
||||
var services []*Service
|
||||
|
|
|
@ -125,14 +125,14 @@ func apiServiceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
vars := mux.Vars(r)
|
||||
service := core.SelectService(utils.StringInt(vars["id"]))
|
||||
service := core.SelectServicer(utils.StringInt(vars["id"]))
|
||||
if service == nil {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(service)
|
||||
json.NewEncoder(w).Encode(service.Select())
|
||||
}
|
||||
|
||||
func apiCreateServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -214,9 +214,13 @@ func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
services := core.SelectServices()
|
||||
services := core.Services()
|
||||
var servicesOut []*types.Service
|
||||
for _, s := range services {
|
||||
servicesOut = append(servicesOut, s.Select())
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(services)
|
||||
json.NewEncoder(w).Encode(servicesOut)
|
||||
}
|
||||
|
||||
func apiUserHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue