-
Notifications
You must be signed in to change notification settings - Fork 3
/
currency.go
72 lines (67 loc) · 1.4 KB
/
currency.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
package labstack
import (
"github.com/go-resty/resty/v2"
"github.com/labstack/labstack-go/currency"
"strconv"
)
type (
CurrencyService struct {
resty *resty.Client
}
)
func (c *CurrencyService) Convert(req *currency.ConvertRequest) (*currency.ConvertResponse, error) {
res := new(currency.ConvertResponse)
err := new(Error)
r, e := c.resty.R().
SetPathParams(map[string]string{
"amount": strconv.FormatFloat(req.Amount, 'f', -1, 64),
"from": req.From,
"to": req.To,
}).
SetResult(res).
SetError(err).
Get("/convert/{amount}/{from}/{to}")
if e != nil {
return nil, &Error{
Message: e.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}
func (c *CurrencyService) List(req *currency.ListRequest) (*currency.ListResponse, error) {
res := new(currency.ListResponse)
err := new(Error)
r, e := c.resty.R().
SetResult(res).
SetError(err).
Get("/list")
if e != nil {
return nil, &Error{
Message: e.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}
func (c *CurrencyService) Rates(req *currency.RatesRequest) (*currency.RatesResponse, error) {
res := new(currency.RatesResponse)
err := new(Error)
r, e := c.resty.R().
SetResult(res).
SetError(err).
Get("/rates")
if e != nil {
return nil, &Error{
Message: e.Error(),
}
}
if isError(r.StatusCode()) {
return nil, err
}
return res, nil
}