From 9372db6279953feb09691c4642e3d47ccc3272d8 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Tue, 5 Nov 2024 09:43:10 -0500 Subject: [PATCH] feat: add remote client constructor --- pkg/workers/client/http.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/workers/client/http.go b/pkg/workers/client/http.go index 98f697372..bcdc78a4b 100644 --- a/pkg/workers/client/http.go +++ b/pkg/workers/client/http.go @@ -28,6 +28,20 @@ func NewLocal() (*SonrClient, error) { } // NewRemote creates a new SonrClient for remote production. -func NewRemote() (*SonrClient, error) { - return &SonrClient{}, nil +func NewRemote(url string) (*SonrClient, error) { + // create http client + client := &SonrClient{ + apiURL: url, + } + // Issue ping to check if server is up + resp, err := http.Get(client.apiURL + "/genesis") + if err != nil { + return nil, err + } + defer resp.Body.Close() + // Check if server is up + if resp.StatusCode != http.StatusOK { + return nil, err + } + return client, nil }