From d421b35e9be1900399026fe1f16e3e482d085615 Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Fri, 20 Mar 2015 20:58:56 +0100 Subject: [PATCH] gofmt -w --- cachet/component.go | 22 +++++++++++----------- cachet/config.go | 18 +++++++++--------- cachet/incident.go | 24 ++++++++++++------------ cachet/metrics.go | 6 +++--- cachet/monitor.go | 26 +++++++++++++------------- cachet/request.go | 4 ++-- main.go | 4 ++-- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/cachet/component.go b/cachet/component.go index f9090f2..e8c12fd 100644 --- a/cachet/component.go +++ b/cachet/component.go @@ -6,14 +6,14 @@ import ( // Component Cachet model type Component struct { - ID int `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Status int `json:"status"` - Link *string `json:"link"` - Order *int `json:"order"` - GroupID *int `json:"group_id"` - CreatedAt *time.Time `json:"created_at"` - UpdatedAt *time.Time `json:"updated_at"` - DeletedAt *time.Time `json:"deleted_at"` -} \ No newline at end of file + ID int `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Status int `json:"status"` + Link *string `json:"link"` + Order *int `json:"order"` + GroupID *int `json:"group_id"` + CreatedAt *time.Time `json:"created_at"` + UpdatedAt *time.Time `json:"updated_at"` + DeletedAt *time.Time `json:"deleted_at"` +} diff --git a/cachet/config.go b/cachet/config.go index 8ccd1bd..b8aa8b5 100644 --- a/cachet/config.go +++ b/cachet/config.go @@ -1,13 +1,13 @@ package cachet import ( - "os" - "fmt" - "flag" - "net/url" - "net/http" - "io/ioutil" "encoding/json" + "flag" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" ) // Static config @@ -15,8 +15,8 @@ var Config CachetConfig // CachetConfig is the monitoring tool configuration type CachetConfig struct { - APIUrl string `json:"api_url"` - APIToken string `json:"api_token"` + APIUrl string `json:"api_url"` + APIToken string `json:"api_token"` Monitors []*Monitor `json:"monitors"` } @@ -73,4 +73,4 @@ func init() { fmt.Printf("No monitors defined!\nSee sample configuration: https://github.com/CastawayLabs/cachet-monitor/blob/master/example.config.json\n") os.Exit(1) } -} \ No newline at end of file +} diff --git a/cachet/incident.go b/cachet/incident.go index 141c877..cc9f791 100644 --- a/cachet/incident.go +++ b/cachet/incident.go @@ -1,22 +1,22 @@ package cachet import ( + "encoding/json" "fmt" "strconv" - "encoding/json" ) // Incident Cachet data model type Incident struct { - ID int `json:"id"` - Name string `json:"name"` - Message string `json:"message"` - Status int `json:"status"`// 4? - HumanStatus string `json:"human_status"` - Component *Component `json:"component"` - ComponentID *int `json:"component_id"` - CreatedAt int `json:"created_at"` - UpdatedAt int `json:"updated_at"` + ID int `json:"id"` + Name string `json:"name"` + Message string `json:"message"` + Status int `json:"status"` // 4? + HumanStatus string `json:"human_status"` + Component *Component `json:"component"` + ComponentID *int `json:"component_id"` + CreatedAt int `json:"created_at"` + UpdatedAt int `json:"updated_at"` } // IncidentData is a response when creating/updating an incident @@ -75,7 +75,7 @@ func (incident *Incident) Send() { incident.ID = data.Incident.ID } - fmt.Println("ID:"+strconv.Itoa(incident.ID)) + fmt.Println("ID:" + strconv.Itoa(incident.ID)) if resp.StatusCode != 200 { fmt.Println("Could not create/update incident!") @@ -118,4 +118,4 @@ func (incident *Incident) SetWatching() { func (incident *Incident) SetFixed() { incident.Status = 4 incident.HumanStatus = "Fixed" -} \ No newline at end of file +} diff --git a/cachet/metrics.go b/cachet/metrics.go index 7a3d9e2..79cf20c 100644 --- a/cachet/metrics.go +++ b/cachet/metrics.go @@ -1,9 +1,9 @@ package cachet import ( + "encoding/json" "fmt" "strconv" - "encoding/json" ) // SendMetric sends lag metric point @@ -16,9 +16,9 @@ func SendMetric(metricID int, delay int64) { "value": delay, }) - resp, _, err := makeRequest("POST", "/metrics/" + strconv.Itoa(metricID) + "/points", jsonBytes) + resp, _, err := makeRequest("POST", "/metrics/"+strconv.Itoa(metricID)+"/points", jsonBytes) if err != nil || resp.StatusCode != 200 { fmt.Printf("Could not log data point!\n%v\n", err) return } -} \ No newline at end of file +} diff --git a/cachet/monitor.go b/cachet/monitor.go index 61a41ae..111a927 100644 --- a/cachet/monitor.go +++ b/cachet/monitor.go @@ -2,24 +2,24 @@ package cachet import ( "fmt" - "time" "net/http" + "time" ) const timeout = time.Duration(time.Second) // Monitor data model type Monitor struct { - Name string `json:"name"` - URL string `json:"url"` - MetricID int `json:"metric_id"` - Threshold float32 `json:"threshold"` - ComponentID *int `json:"component_id"` - ExpectedStatusCode int `json:"expected_status_code"` + Name string `json:"name"` + URL string `json:"url"` + MetricID int `json:"metric_id"` + Threshold float32 `json:"threshold"` + ComponentID *int `json:"component_id"` + ExpectedStatusCode int `json:"expected_status_code"` - History []bool `json:"-"` - LastFailReason *string `json:"-"` - Incident *Incident `json:"-"` + History []bool `json:"-"` + LastFailReason *string `json:"-"` + Incident *Incident `json:"-"` } // Run loop @@ -66,7 +66,7 @@ func (monitor *Monitor) AnalyseData() { } t := (float32(numDown) / float32(len(monitor.History))) * 100 - fmt.Printf("%s %.2f%% Down at %v. Threshold: %.2f%%\n", monitor.Url, t, time.Now().UnixNano() / int64(time.Second), monitor.Threshold) + fmt.Printf("%s %.2f%% Down at %v. Threshold: %.2f%%\n", monitor.Url, t, time.Now().UnixNano()/int64(time.Second), monitor.Threshold) if len(monitor.History) != 10 { // not enough data @@ -78,7 +78,7 @@ func (monitor *Monitor) AnalyseData() { fmt.Println("Creating incident...") monitor.Incident = &Incident{ - Name: monitor.Name, + Name: monitor.Name, Message: monitor.Name + " failed", } @@ -107,4 +107,4 @@ func (monitor *Monitor) AnalyseData() { func getMs() int64 { return time.Now().UnixNano() / int64(time.Millisecond) -} \ No newline at end of file +} diff --git a/cachet/request.go b/cachet/request.go index bc912c6..644eb76 100644 --- a/cachet/request.go +++ b/cachet/request.go @@ -7,7 +7,7 @@ import ( ) func makeRequest(requestType string, url string, reqBody []byte) (*http.Response, []byte, error) { - req, err := http.NewRequest(requestType, Config.APIUrl + url, bytes.NewBuffer(reqBody)) + req, err := http.NewRequest(requestType, Config.APIUrl+url, bytes.NewBuffer(reqBody)) req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Cachet-Token", Config.APIToken) @@ -22,4 +22,4 @@ func makeRequest(requestType string, url string, reqBody []byte) (*http.Response body, _ := ioutil.ReadAll(res.Body) return res, body, nil -} \ No newline at end of file +} diff --git a/main.go b/main.go index b419901..fd596b6 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "time" "github.com/castawaylabs/cachet-monitor/cachet" + "time" ) func main() { @@ -19,7 +19,7 @@ func main() { fmt.Println() ticker := time.NewTicker(time.Second) - for _ = range ticker.C { + for range ticker.C { for _, monitor := range cachet.Config.Monitors { go monitor.Run() }