Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #38 from Anusha-Rapido/t38-health
Browse files Browse the repository at this point in the history
Added Health Check Method for Tile38
  • Loading branch information
shadowspore authored Jun 23, 2021
2 parents e0e10e6 + 41b5690 commit f569215
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"log"

"github.com/xjem/t38c/transport"
"github.com/tidwall/gjson"
"github.com/xjem/t38c/transport"
)

// Client allows you to interact with the Tile38 server.
Expand Down Expand Up @@ -80,6 +80,11 @@ func NewWithExecutor(exec Executor, debug bool) (*Client, error) {
return nil, err
}

// Health check can be used this way to test the readiness of tile38
// if healthError := client.HealthZ(); healthError != nil {
// return nil, healthError
// }

client.Webhooks = &Hooks{client}
client.Geofence = &Geofence{client}
client.Keys = &Keys{client}
Expand Down
18 changes: 18 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ func (client *Client) Ping() error {

return nil
}

// Health Check
func (client *Client) HealthZ() error {
var response struct {
OK bool `json:"ok"`
}

err := client.jExecute(&response, "HEALTHZ")
if err != nil {
return err
}

if !response.OK {
return fmt.Errorf("health check failed: %v", response)
}

return nil
}

0 comments on commit f569215

Please sign in to comment.