Working get notification from hhtestnet.com

botanswer
AnisB 4 years ago
parent f3f1a8403d
commit 0f8c40fa12

@ -9,38 +9,33 @@ import (
"net/http"
// "strings"
"io/ioutil"
"encoding/json"
)
const (
ApiEndpoint = "https://hodlhodl.com/api/v1"
TestApiEndpoint = "https://hhtestnet.com/api/v1"
ApiKey = "***REMOVED***"
// APIEndpoint = "https://hodlhodl.com/api/v1"
TestAPIEndpoint = "https://hhtestnet.com/api/v1"
APIKEY = "***REMOVED***"
)
// Notification export
type Notification struct {
Id int `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
}
type response struct {
Status string `json:"status"`
ExchangeRateProviders []struct {
Name string `json:"name"`
CurrencyCodes []string `json:"currency_codes"`
} `json:"exchange_rate_providers"`
Status string `json:"status"`
Notifications []struct {
ID string `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
} `json:"notifications"`
}
func main() {
//body:= strings.NewReader(' -X POST -H "Authorization: Bearer ***REMOVED***" -H "Content-Type: application/json"`)
req, err := http.NewRequest("POST", TestApiEndpoint + "/notifications/read", nil)
req, err := http.NewRequest("POST", TestAPIEndpoint + "/notifications/read", nil)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Authorization", "Bearer " + ApiKey)
req.Header.Add("Authorization", "Bearer " + APIKEY)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
@ -52,8 +47,12 @@ func main() {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
} else {
res:= Notification{}
json.Unmarshal([]byte(body), &res)
fmt.Println("RESULT", res)
fmt.Println("RESULTAT", string(body))
}
fmt.Println(string(body))
defer resp.Body.Close()
}

Loading…
Cancel
Save