From 0f8c40fa129d0c72d46f0b3627cd852b4b01ea3e Mon Sep 17 00:00:00 2001 From: AnisB Date: Wed, 9 Sep 2020 19:33:41 +0100 Subject: [PATCH] Working get notification from hhtestnet.com --- main.go | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index fbac765..417d4b6 100644 --- a/main.go +++ b/main.go @@ -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() }