mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 18:31:41 +00:00
feat: add remote client constructor
This commit is contained in:
@@ -28,6 +28,20 @@ func NewLocal() (*SonrClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewRemote creates a new SonrClient for remote production.
|
// NewRemote creates a new SonrClient for remote production.
|
||||||
func NewRemote() (*SonrClient, error) {
|
func NewRemote(url string) (*SonrClient, error) {
|
||||||
return &SonrClient{}, nil
|
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user