diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2022-04-19 21:58:23 +0200 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2022-04-19 21:58:23 +0200 |
commit | 57440c5f840dd5d4dadd80f69467a3b1450e6027 (patch) | |
tree | 032b6a106abe534f2e9cb27deb653525bf42a34c /gosrc/requests.go | |
parent | refactor, readme, gui hooks, and more (diff) | |
download | smith-57440c5f840dd5d4dadd80f69467a3b1450e6027.tar.gz smith-57440c5f840dd5d4dadd80f69467a3b1450e6027.tar.bz2 smith-57440c5f840dd5d4dadd80f69467a3b1450e6027.tar.xz smith-57440c5f840dd5d4dadd80f69467a3b1450e6027.tar.zst smith-57440c5f840dd5d4dadd80f69467a3b1450e6027.zip |
improve response display, now with 400% more unmarshalling (smith_v_0.1.0)
Diffstat (limited to '')
-rw-r--r-- | gosrc/requests.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gosrc/requests.go b/gosrc/requests.go index 6df7bc6..9110c89 100644 --- a/gosrc/requests.go +++ b/gosrc/requests.go @@ -7,6 +7,8 @@ package main import ( + "encoding/json" + "io" "log" "net/http" "strings" @@ -59,6 +61,31 @@ func getRequestType(name string) string { } } +func displayResponse(node_name string, response *http.Response, output *string) { + requestType := getRequestType(node_name) + body, _ := io.ReadAll(response.Body) + var outputFormatted string + + switch (requestType) { + case GET_Targets.status: + var structuredRep AccountStatusResponse + json.Unmarshal(body, &structuredRep) + outputFormatted = + "Status [" + structuredRep.Data + "]\n" + case GET_Targets.address: + var structuredRep DepositAddressResponse + json.Unmarshal(body, &structuredRep) + outputFormatted = + "Coin [" + structuredRep.Coin + "]\n" + + "Address [" + structuredRep.Address + "]\n" + + "Url [" + structuredRep.Url + "]\n" + + "Tag [" + structuredRep.Tag + "]\n" + default: + outputFormatted = string(body) + } + *output = outputFormatted +} + // Sign payload using openssl func signRequest(body string, key string) string { // run pipeline |