-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (54 loc) · 1.35 KB
/
Copy pathmain.go
File metadata and controls
61 lines (54 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type ExchangeRate struct {
Data []CurrencyData `json:"data"`
Epoch float64 `json:"epoch"`
Timestamp string `json:"timestamp"`
}
type CurrencyData struct {
Currency string `json:"currency"`
Buy string `json:"buy"`
Sell string `json:"sell"`
}
func main() {
res, err := http.Get("https://myanmar-currency-api.github.io/api/latest.json")
if err != nil {
panic(err)
}
defer res.Body.Close()
//fmt.Println(res)
if res.StatusCode != 200 {
panic("API not good!")
}
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
//fmt.Println(string(body))
var exchange ExchangeRate
err = json.Unmarshal(body, &exchange)
if err != nil {
panic(err)
}
//currencyType,sell,buy:=.
//fmt.Println(exchange.Data)
people := []CurrencyData{}
//currencyMap := make(map[string]string)
for _, currencyData := range exchange.Data {
if currencyData.Currency == "USD" || currencyData.Currency == "THB" || currencyData.Currency == "SGD" {
newData := CurrencyData{
Currency: "Currency : " + currencyData.Currency + ",",
Buy: "Sell Price : " + currencyData.Sell + ",",
Sell: "Buy Price : " + currencyData.Buy,
}
people = append(people, newData)
}
}
fmt.Println("Date : ", exchange.Timestamp)
fmt.Println("information : ", people)
}