More 'improvements' based on goreportcard.com

This commit is contained in:
Matej Kramny
2015-03-20 20:52:57 +01:00
parent 3d0b0c88e1
commit cdf51d89f6
5 changed files with 16 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ import (
"time" "time"
) )
// Cachet component model // Component Cachet model
type Component struct { type Component struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
@@ -12,7 +12,7 @@ type Component struct {
Status int `json:"status"` Status int `json:"status"`
Link *string `json:"link"` Link *string `json:"link"`
Order *int `json:"order"` Order *int `json:"order"`
GroupId *int `json:"group_id"` GroupID *int `json:"group_id"`
CreatedAt *time.Time `json:"created_at"` CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"` UpdatedAt *time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at"` DeletedAt *time.Time `json:"deleted_at"`

View File

@@ -13,7 +13,7 @@ import (
// Static config // Static config
var Config CachetConfig var Config CachetConfig
// Monitoring tool configuration // CachetConfig is the monitoring tool configuration
type CachetConfig struct { type CachetConfig struct {
APIUrl string `json:"api_url"` APIUrl string `json:"api_url"`
APIToken string `json:"api_token"` APIToken string `json:"api_token"`

View File

@@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
) )
// Cachet Incident data model // Incident Cachet data model
type Incident struct { type Incident struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
@@ -14,22 +14,22 @@ type Incident struct {
Status int `json:"status"`// 4? Status int `json:"status"`// 4?
HumanStatus string `json:"human_status"` HumanStatus string `json:"human_status"`
Component *Component `json:"component"` Component *Component `json:"component"`
ComponentId *int `json:"component_id"` ComponentID *int `json:"component_id"`
CreatedAt int `json:"created_at"` CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"` UpdatedAt int `json:"updated_at"`
} }
// Response when creating/updating an incident // IncidentData is a response when creating/updating an incident
type IncidentData struct { type IncidentData struct {
Incident Incident `json:"data"` Incident Incident `json:"data"`
} }
// from API /incidents // IncidentList - from API /incidents
type IncidentList struct { type IncidentList struct {
Incidents []Incident `json:"data"` Incidents []Incident `json:"data"`
} }
// Get list of incidents // GetIncidents - Get list of incidents
func GetIncidents() []Incident { func GetIncidents() []Incident {
_, body, err := makeRequest("GET", "/incidents", nil) _, body, err := makeRequest("GET", "/incidents", nil)
if err != nil { if err != nil {
@@ -45,7 +45,7 @@ func GetIncidents() []Incident {
return data.Incidents return data.Incidents
} }
// Create or Update incident // Send - Create or Update incident
func (incident *Incident) Send() { func (incident *Incident) Send() {
jsonBytes, err := json.Marshal(incident) jsonBytes, err := json.Marshal(incident)
if err != nil { if err != nil {
@@ -83,7 +83,7 @@ func (incident *Incident) Send() {
} }
// Get the same incident. // Get the same incident.
// Updates incident.ID // GetSimilarIncidentId Updates incident.ID
func (incident *Incident) GetSimilarIncidentId() { func (incident *Incident) GetSimilarIncidentId() {
incidents := GetIncidents() incidents := GetIncidents()
@@ -96,25 +96,25 @@ func (incident *Incident) GetSimilarIncidentId() {
} }
} }
// Set status to Investigating // SetInvestigating sets status to Investigating
func (incident *Incident) SetInvestigating() { func (incident *Incident) SetInvestigating() {
incident.Status = 1 incident.Status = 1
incident.HumanStatus = "Investigating" incident.HumanStatus = "Investigating"
} }
// Set status to Identified // SetIdentified sets status to Identified
func (incident *Incident) SetIdentified() { func (incident *Incident) SetIdentified() {
incident.Status = 2 incident.Status = 2
incident.HumanStatus = "Identified" incident.HumanStatus = "Identified"
} }
// Set status to Watching // SetWatching sets status to Watching
func (incident *Incident) SetWatching() { func (incident *Incident) SetWatching() {
incident.Status = 3 incident.Status = 3
incident.HumanStatus = "Watching" incident.HumanStatus = "Watching"
} }
// Set status to Fixed // SetFixed sets status to Fixed
func (incident *Incident) SetFixed() { func (incident *Incident) SetFixed() {
incident.Status = 4 incident.Status = 4
incident.HumanStatus = "Fixed" incident.HumanStatus = "Fixed"

View File

@@ -6,7 +6,7 @@ import (
"encoding/json" "encoding/json"
) )
// Send lag metric point // SendMetric sends lag metric point
func SendMetric(metricID int, delay int64) { func SendMetric(metricID int, delay int64) {
if metricID <= 0 { if metricID <= 0 {
return return

View File

@@ -55,7 +55,7 @@ func (monitor *Monitor) doRequest() bool {
return resp.StatusCode == monitor.ExpectedStatusCode return resp.StatusCode == monitor.ExpectedStatusCode
} }
// Decides if the monitor is statistically up or down and creates / resolves an incident // AnalyseData decides if the monitor is statistically up or down and creates / resolves an incident
func (monitor *Monitor) AnalyseData() { func (monitor *Monitor) AnalyseData() {
// look at the past few incidents // look at the past few incidents
numDown := 0 numDown := 0