From 57440c5f840dd5d4dadd80f69467a3b1450e6027 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 19 Apr 2022 21:58:23 +0200 Subject: improve response display, now with 400% more unmarshalling (smith_v_0.1.0) --- README.org | 16 ++++++++++++++++ default.json | 5 +++++ gosrc/README.org | 16 ---------------- gosrc/default.json | 5 ----- gosrc/main.go | 7 +++---- gosrc/requests.go | 27 +++++++++++++++++++++++++++ gosrc/structs.go | 45 ++++++++++++++++++++++++++++++++++++++------- 7 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 README.org create mode 100644 default.json delete mode 100644 gosrc/README.org delete mode 100644 gosrc/default.json diff --git a/README.org b/README.org new file mode 100644 index 0000000..a2c21b9 --- /dev/null +++ b/README.org @@ -0,0 +1,16 @@ +#+title: Readme +#+author: salade +#+email: salad@jozanofastora.xyz + +* Smith +Smith is a very good friend of mine, and a robot +His purpose is to make me money, or as we call it in France, *Cesterces*.... + +** Building +Just type +src_bash[build]{make} +And you will have a very nice executable called smith + +** Usage +You will find at the source of this repository a file called *default.json*, in which you must insert the correct value to be able to use this program +Given how early in production this program is, you might feel a little restricted in what you can ask my good friend to do. Don't worry, traveller... Enjoy the ride and the view diff --git a/default.json b/default.json new file mode 100644 index 0000000..b1d652f --- /dev/null +++ b/default.json @@ -0,0 +1,5 @@ +{ + "public_key": "hello", + "secret_key": "hehehe", + "mirror": "heheheheheh" +} diff --git a/gosrc/README.org b/gosrc/README.org deleted file mode 100644 index a2c21b9..0000000 --- a/gosrc/README.org +++ /dev/null @@ -1,16 +0,0 @@ -#+title: Readme -#+author: salade -#+email: salad@jozanofastora.xyz - -* Smith -Smith is a very good friend of mine, and a robot -His purpose is to make me money, or as we call it in France, *Cesterces*.... - -** Building -Just type -src_bash[build]{make} -And you will have a very nice executable called smith - -** Usage -You will find at the source of this repository a file called *default.json*, in which you must insert the correct value to be able to use this program -Given how early in production this program is, you might feel a little restricted in what you can ask my good friend to do. Don't worry, traveller... Enjoy the ride and the view diff --git a/gosrc/default.json b/gosrc/default.json deleted file mode 100644 index b1d652f..0000000 --- a/gosrc/default.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "public_key": "hello", - "secret_key": "hehehe", - "mirror": "heheheheheh" -} diff --git a/gosrc/main.go b/gosrc/main.go index 58ecfe6..edc3033 100644 --- a/gosrc/main.go +++ b/gosrc/main.go @@ -8,7 +8,6 @@ package main import ( "encoding/json" - "io" "io/ioutil" "log" "os" @@ -103,7 +102,8 @@ func ui_loop(config Config) error { p1.Border = true p2.Border = true - output.Border = false + output.Border = true + output.TextStyle.Fg = ui.ColorGreen p1.Title = "Active Mirror" p2.Title = "Balance" @@ -160,8 +160,7 @@ func ui_loop(config Config) error { if rep == nil || err != nil { output.Text = "something went wrong :^{" } else { - body, _ := io.ReadAll(rep.Body) - output.Text = string(body) + displayResponse(l.SelectedNode().Value.String(), rep, &output.Text) defer rep.Body.Close() } } 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 diff --git a/gosrc/structs.go b/gosrc/structs.go index 3f2fa74..49843a0 100644 --- a/gosrc/structs.go +++ b/gosrc/structs.go @@ -6,13 +6,6 @@ package main -// config.json content -type Config struct { - Public_key string - Secret_key string - Mirror string -} - // urls to hit on mirror type Targets struct { getall string @@ -37,3 +30,41 @@ var POST_Targets = Targets { snapshot: "/null", null: "/null", } + +// config.json content +type Config struct { + Public_key string + Secret_key string + Mirror string +} + +// +// ---- responses ---- +// +type AccountStatusResponse struct { + Data string +} + +type AccountSnapshotResponseMain struct { + Code float64 + Msg string + SnapshotVos map[string]interface{} +} + +type AccountSnapshotResponseVos struct { + Data map[string]interface{} + Type string + UpdateTime float64 +} + +type AccountSnapshotResponseData struct { + Balances []interface{} + TotalAssetOfBtc float64 +} + +type DepositAddressResponse struct { + Address string + Coin string + Tag string + Url string +} -- cgit v1.2.3