@@ -14,7 +14,7 @@ import (
1414)
1515
1616const (
17- TIMEOUT = 3 //seconds
17+ TIMEOUT = 3 * time . Second
1818 GITHUB = "https://status.github.com/api/status.json"
1919 CODECOV = "https://wdzsn5dlywj9.statuspage.io/api/v2/status.json"
2020 TRAVIS = "https://pnpcptp8xh9k.statuspage.io/api/v2/status.json"
@@ -40,20 +40,13 @@ func updaterInit() {
4040 ticker := time .NewTicker (1 * time .Minute )
4141 updateState (DataStore )
4242 go func () {
43- for {
44- select {
45- case <- ticker .C :
46- updateState (DataStore )
47- }
43+ for _ = range ticker .C {
44+ updateState (DataStore )
4845 }
4946 }()
5047}
5148
52- func statusFetch (url string ) (* []byte , error ) {
53- timeout := time .Duration (TIMEOUT * time .Second )
54- client := http.Client {
55- Timeout : timeout ,
56- }
49+ func statusFetch (url string , client http.Client ) ([]byte , error ) {
5750 resp , err := client .Get (url )
5851 if err != nil {
5952 return nil , err
@@ -63,38 +56,44 @@ func statusFetch(url string) (*[]byte, error) {
6356 if err != nil {
6457 return nil , err
6558 }
66- return & body , nil
59+ return body , nil
6760}
6861
6962func updateState (store * state.Store ) {
70- var wg sync.WaitGroup
63+ wg := sync.WaitGroup {}
64+
7165 sources := []string {GITHUB , TRAVIS , QUAY , CODECOV }
7266 // match the length of sources
73- wg .Add (4 )
67+ wg .Add (len (sources ))
68+
69+ timeout := time .Duration (TIMEOUT )
70+ client := http.Client {
71+ Timeout : timeout ,
72+ }
7473
7574 for _ , url := range sources {
7675 go func (url string ) {
7776 log .Printf ("Started Fetching: %s" , url )
7877 InflightStatus .Inc ()
7978 defer InflightStatus .Dec ()
8079 defer wg .Done ()
81- body , err := statusFetch (url )
80+ body , err := statusFetch (url , client )
8281 if err != nil {
8382 log .Printf ("Error fetching: %s, %s" , url , err )
8483 return
8584 }
8685 log .Printf ("Succeeded fetching: %s" , url )
8786
88- var good bool
87+ var parser parsing. Parser
8988 switch url {
9089 case GITHUB :
91- source := parsing.GithubStatus {}
92- good = source .Parse (body )
90+ parser = parsing .GithubParser
9391 case CODECOV , TRAVIS , QUAY :
94- source := parsing.StatusPageStatus {}
95- good = source .Parse (body )
92+ parser = parsing .StatusPageParser
93+ default :
94+ parser = parsing .DefaultParser
9695 }
97-
96+ good := parser ( body )
9897 r := state.Refined {
9998 Good : good ,
10099 SourceMessage : body ,
0 commit comments