-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (61 loc) · 2.47 KB
/
main.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/voyago/converter/environment"
"github.com/voyago/converter/pkg/conversion"
"github.com/voyago/converter/pkg/model"
"github.com/voyago/converter/pkg/store"
"github.com/voyago/converter/pkg/store/handler/currencyLayer"
)
func main() {
divider("| CURRENCY LAYER API DATA |")
fetchCurrencyLayerData()
divider("| TESTING DATA |")
fetchTestingData()
}
func fetchCurrencyLayerData() {
env, _ := environment.Make("converter-test")
if env.Get(currencyLayer.ApiKeyName) == "" {
fmt.Println("Skipping ...")
fmt.Println("Please, add a valid key for your currency layer setup. Ref: ", currencyLayer.ApiKeyName)
return
}
manager, _ := store.Make(store.NewCurrencyLayerRequest(env, "SGD"))
currencies, _ := manager.GetExchangeRates()
usd, _ := currencies.Find("USD")
fmt.Println("--- Environment")
fmt.Println(fmt.Sprintf("App name: %s", env.Get("APP_NAME")))
fmt.Println(fmt.Sprintf("App env: %s [live?: %v]\n", env.Get(environment.EnvKey), env.IsLive()))
fmt.Println("--- Currencies exchange rate")
fmt.Println("Available currencies rate:", currencies.Count())
fmt.Println("USD rate:", usd.Rate)
fmt.Println("\n--- Conversions")
converter := conversion.Make(*manager)
price, _ := model.MakePrice(usd, 1)
result, _ := converter.Convert(price)
fmt.Println(fmt.Sprintf("Result: [%s], Amount: [%.2f]", result.ToString(), result.ToFloat()))
}
func fetchTestingData() {
env, _ := environment.MakeWith("converter-test", ".test.env.example")
manager, _ := store.Make(store.NewCurrencyLayerRequest(env, "SGD"))
rates, _ := manager.GetExchangeRates()
sgd, _ := rates.Find("SGD")
fmt.Println("--- Environment")
fmt.Println(fmt.Sprintf("App name: %s", env.Get("APP_NAME")))
fmt.Println(fmt.Sprintf("App env: %s [live?: %v]\n", env.Get(environment.EnvKey), env.IsLive()))
fmt.Println("--- Currencies exchange rate")
fmt.Println("Available currencies rate:", rates.Count())
fmt.Println("SGD rate:", sgd.Rate)
fmt.Println("\n--- Conversions")
converter := conversion.Make(*manager)
price, _ := model.MakePrice(sgd, 1)
result, _ := converter.Convert(price)
fmt.Println(fmt.Sprintf("Result: [%s], Amount: [%.2f]", result.ToString(), result.ToFloat()))
}
func divider(message string) {
fmt.Println("")
fmt.Println("+ --------------------------------------------------- +")
fmt.Println(message)
fmt.Println("+ --------------------------------------------------- +")
fmt.Println("")
}