From 2417954770c7928ba7e74213d06ff51d712c753d Mon Sep 17 00:00:00 2001 From: AnisB Date: Sun, 6 Sep 2020 05:14:28 +0100 Subject: [PATCH] working api post --- main.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..7144091 --- /dev/null +++ b/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "fmt" + "net/http" +// "strings" + "io/ioutil" +) + +const ( + ApiEndpoint = "https://hodlhodl.com/api/v1" + TestApiEndpoint = "https://hhtestnet.com/api/v1" + ApiKey = "***REMOVED***" +) + + +type response struct { + Status string `json:"status"` + ExchangeRateProviders []struct { + Name string `json:"name"` + CurrencyCodes []string `json:"currency_codes"` + } `json:"exchange_rate_providers"` +} + +func main() { + fmt.Println("hello world") + //body:= strings.NewReader(' -X POST -H "Authorization: Bearer ***REMOVED***" -H "Content-Type: application/json"`) + req, err := http.NewRequest("POST", TestApiEndpoint + "/notifications/read", nil) + if err != nil { + fmt.Println(err) + } + req.Header.Add("Authorization", "Bearer " + ApiKey) + req.Header.Set("Content-Type", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err!= nil { + fmt.Println(err) + } + + fmt.Println(resp.Status) + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + fmt.Println(err) + } + fmt.Println(string(body)) + + defer resp.Body.Close() + +}