Skip to content

Commit

Permalink
fix(exchange): unneeded string
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Jul 12, 2024
1 parent 3193a21 commit 5b7b9a4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/exchange/engines/currencyapi/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (e Exchange) Exchange(base currency.Currency) (currency.Currencies, error)
}

// Unmarshal the response.
dataRates, err := extractRatesFromResp(string(body), base)
dataRates, err := e.extractRates(string(body), base)
if err != nil {
return nil, fmt.Errorf("failed to extract rates from response: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/engines/currencyapi/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// Rates field is named the same as base currency.
func extractRatesFromResp(resp string, base currency.Currency) (map[string]float64, error) {
func (e Exchange) extractRates(resp string, base currency.Currency) (map[string]float64, error) {
pattern := `"` + base.Lower() + `":\s*{[^}]*}`
regexp := regexp.MustCompile(pattern)
match := regexp.FindString(resp)
Expand Down
8 changes: 3 additions & 5 deletions src/exchange/engines/currencyapi/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"github.com/hearchco/agent/src/exchange/currency"
)

type Exchange struct {
apiUrl string
}
type Exchange struct{}

func New() Exchange {
return Exchange{apiUrl}
return Exchange{}
}

func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string {
return e.apiUrl + "/" + base.Lower() + ".json"
return apiUrl + "/" + base.Lower() + ".json"
}
8 changes: 3 additions & 5 deletions src/exchange/engines/exchangerateapi/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"github.com/hearchco/agent/src/exchange/currency"
)

type Exchange struct {
apiUrl string
}
type Exchange struct{}

func New() Exchange {
return Exchange{apiUrl}
return Exchange{}
}

func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string {
return e.apiUrl + "/" + base.String()
return apiUrl + "/" + base.String()
}
6 changes: 2 additions & 4 deletions src/exchange/engines/frankfurter/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"github.com/hearchco/agent/src/exchange/currency"
)

type Exchange struct {
apiUrl string
}
type Exchange struct{}

func New() Exchange {
return Exchange{apiUrl}
return Exchange{}
}

func (e Exchange) apiUrlWithBaseCurrency(base currency.Currency) string {
Expand Down

0 comments on commit 5b7b9a4

Please sign in to comment.