Skip to content

Instantly share code, notes, and snippets.

@Nearhan
Created January 16, 2017 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nearhan/0939c364b5a1dce36a211e6a0916035d to your computer and use it in GitHub Desktop.
Save Nearhan/0939c364b5a1dce36a211e6a0916035d to your computer and use it in GitHub Desktop.
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