Created
January 16, 2017 00:37
-
-
Save Nearhan/0939c364b5a1dce36a211e6a0916035d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"sync" | |
) | |
type IngestionClient struct { | |
Svs []IngestionSvc | |
sync *sync.WaitGroup | |
} | |
type IngestionMgr interface { | |
} | |
type IngestionSvc struct { | |
Addr string | |
Status string `json:"ingestionStatus"` | |
} | |
func MakeIngestionClient(h *HootClient) (*IngestionClient, error) { | |
var i IngestionClient | |
services, err := getIngestionAddrs(h.Consul) | |
if err != nil { | |
return nil, err | |
} | |
i.Svs = services | |
return &i, nil | |
} | |
func (i *IngestionClient) Status() error { | |
return i.statusLogic("status") | |
} | |
func (i *IngestionClient) Pause() error { | |
return i.statusLogic("pause") | |
} | |
func (i *IngestionClient) Start() error { | |
return i.statusLogic("start") | |
} | |
func (i *IngestionClient) statusLogic(action string) error { | |
for _, s := range i.Svs { | |
{ | |
url := fmt.Sprintf("http://%s/%s", s.Addr, action) | |
fmt.Println(url) | |
req, err := http.NewRequest("GET", url, nil) | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
return err | |
} | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
return err | |
} | |
json.Unmarshal(body, &s) | |
fmt.Println(s) | |
} | |
} | |
fmt.Println(i.Svs) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment