|
|
|
@ -153,7 +153,7 @@ func NewClient(urls []string, opts ...ClientOption) *Client { |
|
|
|
|
|
|
|
|
|
func (e *Client) FetchApps(ctx context.Context) []Application { |
|
|
|
|
var m ApplicationsRootResponse |
|
|
|
|
if err := e.do(ctx, "GET", []string{"apps"}, nil, &m); err != nil { |
|
|
|
|
if err := e.do(ctx, http.MethodGet, []string{"apps"}, nil, &m); err != nil { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ func (e *Client) FetchApps(ctx context.Context) []Application { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) FetchAppInstances(ctx context.Context, appID string) (m Application, err error) { |
|
|
|
|
err = e.do(ctx, "GET", []string{"apps", appID}, nil, &m) |
|
|
|
|
err = e.do(ctx, http.MethodGet, []string{"apps", appID}, nil, &m) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -174,21 +174,21 @@ func (e *Client) FetchAppUpInstances(ctx context.Context, appID string) []Instan |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) FetchAppInstance(ctx context.Context, appID string, instanceID string) (m Instance, err error) { |
|
|
|
|
err = e.do(ctx, "GET", []string{"apps", appID, instanceID}, nil, &m) |
|
|
|
|
err = e.do(ctx, http.MethodGet, []string{"apps", appID, instanceID}, nil, &m) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) FetchInstance(ctx context.Context, instanceID string) (m Instance, err error) { |
|
|
|
|
err = e.do(ctx, "GET", []string{"instances", instanceID}, nil, &m) |
|
|
|
|
err = e.do(ctx, http.MethodGet, []string{"instances", instanceID}, nil, &m) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) Out(ctx context.Context, appID, instanceID string) error { |
|
|
|
|
return e.do(ctx, "PUT", []string{"apps", appID, instanceID, fmt.Sprintf("status?value=%s", statusOutOfService)}, nil, nil) |
|
|
|
|
return e.do(ctx, http.MethodPut, []string{"apps", appID, instanceID, fmt.Sprintf("status?value=%s", statusOutOfService)}, nil, nil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) Down(ctx context.Context, appID, instanceID string) error { |
|
|
|
|
return e.do(ctx, "PUT", []string{"apps", appID, instanceID, fmt.Sprintf("status?value=%s", statusDown)}, nil, nil) |
|
|
|
|
return e.do(ctx, http.MethodPut, []string{"apps", appID, instanceID, fmt.Sprintf("status?value=%s", statusDown)}, nil, nil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) FetchAllUpInstances(ctx context.Context) []Instance { |
|
|
|
@ -200,7 +200,7 @@ func (e *Client) Register(ctx context.Context, ep Endpoint) error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) Deregister(ctx context.Context, appID, instanceID string) error { |
|
|
|
|
if err := e.do(ctx, "DELETE", []string{"apps", appID, instanceID}, nil, nil); err != nil { |
|
|
|
|
if err := e.do(ctx, http.MethodDelete, []string{"apps", appID, instanceID}, nil, nil); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
go e.cancelHeartbeat(appID) |
|
|
|
@ -239,7 +239,7 @@ func (e *Client) registerEndpoint(ctx context.Context, ep Endpoint) error { |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
return e.do(ctx, "POST", []string{"apps", ep.AppID}, bytes.NewReader(body), nil) |
|
|
|
|
return e.do(ctx, http.MethodPost, []string{"apps", ep.AppID}, bytes.NewReader(body), nil) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (e *Client) Heartbeat(ep Endpoint) { |
|
|
|
@ -257,7 +257,7 @@ func (e *Client) Heartbeat(ep Endpoint) { |
|
|
|
|
case <-e.keepalive[ep.AppID]: |
|
|
|
|
return |
|
|
|
|
case <-ticker.C: |
|
|
|
|
if err := e.do(e.ctx, "PUT", []string{"apps", ep.AppID, ep.InstanceID}, nil, nil); err != nil { |
|
|
|
|
if err := e.do(e.ctx, http.MethodPut, []string{"apps", ep.AppID, ep.InstanceID}, nil, nil); err != nil { |
|
|
|
|
if retryCount++; retryCount > heartbeatRetry { |
|
|
|
|
_ = e.registerEndpoint(e.ctx, ep) |
|
|
|
|
retryCount = 0 |
|
|
|
|