mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 09:51:39 +00:00
34 lines
749 B
Go
34 lines
749 B
Go
package client
|
|||
|
|
|
||
|
|
import "net/http"
|
||
|
|
|
||
|
|
// SonrClient is a REST HTTP client for Querying Module Endpoints
|
||
|
|
// for the Sonr blockchain.
|
||
|
|
type SonrClient struct {
|
||
|
|
apiURL string
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewLocal creates a new SonrClient for local development.
|
||
|
|
func NewLocal() (*SonrClient, error) {
|
||
|
|
// create http client
|
||
|
|
client := &SonrClient{
|
||
|
|
apiURL: "http://localhost:1323",
|
||
|
|
}
|
||
|
|
// 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
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewRemote creates a new SonrClient for remote production.
|
||
|
|
func NewRemote() (*SonrClient, error) {
|
||
|
|
return &SonrClient{}, nil
|
||
|
|
}
|