mirror-nourybot/internal/commands/decapi/currency.go
2023-01-04 15:32:17 +01:00

39 lines
813 B
Go

package decapi
import (
"fmt"
"io"
"net/http"
"go.uber.org/zap"
)
// ()currency 10 USD to EUR
func Currency(currAmount, currFrom, currTo string) (string, error) {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
basePath := "https://decapi.me/misc/currency/"
from := fmt.Sprintf("?from=%s", currFrom)
to := fmt.Sprintf("&to=%s", currTo)
value := fmt.Sprintf("&value=%s", currAmount)
// https://decapi.me/misc/currency/?from=usd&to=usd&value=10
resp, err := http.Get(fmt.Sprint(basePath + from + to + value))
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
sugar.Error(err)
return "Something went wrong FeelsBadMan", err
}
reply := string(body)
return reply, nil
}