Working get notification from hhtestnet.com

botanswer
AnisB 4 years ago
parent f3f1a8403d
commit 0f8c40fa12

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

Loading…
Cancel
Save