diff options
-rw-r--r-- | README.org (renamed from gosrc/README.org) | 0 | ||||
-rw-r--r-- | default.json (renamed from gosrc/default.json) | 0 | ||||
-rw-r--r-- | gosrc/main.go | 7 | ||||
-rw-r--r-- | gosrc/requests.go | 27 | ||||
-rw-r--r-- | gosrc/structs.go | 45 |
5 files changed, 68 insertions, 11 deletions
diff --git a/gosrc/README.org b/README.org index a2c21b9..a2c21b9 100644 --- a/gosrc/README.org +++ b/README.org diff --git a/gosrc/default.json b/default.json index b1d652f..b1d652f 100644 --- a/gosrc/default.json +++ b/default.json 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 +} |