parent
0f167919d2
commit
86af93152c
@ -0,0 +1,4 @@
|
||||
package httpQuery
|
||||
|
||||
type HTTPQuery struct {
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package httpQuery
|
||||
|
||||
var httpQuery HTTPQuery
|
@ -0,0 +1,33 @@
|
||||
package httpQuery
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GET(url string) ([]byte, error) {
|
||||
method := "GET"
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(method, url, nil)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package httpQuery
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
body, err := GET("https://api.ethermine.org/poolStats")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Log(string(body))
|
||||
|
||||
}
|
Loading…
Reference in new issue