Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5451899e48 | |||
| 6dd11c6441 |
@@ -19,8 +19,8 @@ type Service struct {
|
||||
port int
|
||||
ttl time.Duration
|
||||
agent *consul.Agent
|
||||
connect *consul.Connect
|
||||
kv *consul.KV
|
||||
catalog *consul.Catalog
|
||||
}
|
||||
|
||||
var ErrServiceUnavailable = fmt.Errorf("Service is unavailable")
|
||||
@@ -40,8 +40,8 @@ func NewService(servAddr, id, name, hostname, domain, pathPrefix string, appPort
|
||||
return nil, err
|
||||
}
|
||||
s.agent = client.Agent()
|
||||
s.connect = client.Connect()
|
||||
s.kv = client.KV()
|
||||
s.catalog = client.Catalog()
|
||||
|
||||
return s, nil
|
||||
}
|
||||
@@ -103,12 +103,12 @@ func (s *Service) Unregister() error {
|
||||
return s.agent.ServiceDeregister(s.GetID())
|
||||
}
|
||||
|
||||
func (s *Service) KV() *consul.KV {
|
||||
return s.kv
|
||||
func (s *Service) Connect() *consul.Connect {
|
||||
return s.connect
|
||||
}
|
||||
|
||||
func (s *Service) Catalog() *consul.Catalog {
|
||||
return s.catalog
|
||||
func (s *Service) KV() *consul.KV {
|
||||
return s.kv
|
||||
}
|
||||
|
||||
func (s *Service) healthCheck() (bool, error) {
|
||||
@@ -117,19 +117,16 @@ func (s *Service) healthCheck() (bool, error) {
|
||||
healthUrl := s.GetFullAddr() + "health"
|
||||
req, err := http.NewRequest(http.MethodGet, healthUrl, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateRequest error: %v\n", err)
|
||||
return false
|
||||
}
|
||||
req.Header.Set("User-Agent", "service/internal")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Printf("SendRequest error: %v\n", err)
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Printf("ResponseCODE: %v -- %v\n", req, resp)
|
||||
return resp.StatusCode == http.StatusOK
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user