Skip to content

Commit

Permalink
add: lint script (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano authored Jan 4, 2025
1 parent c472f80 commit a35e182
Show file tree
Hide file tree
Showing 35 changed files with 173 additions and 94 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
golangci_version=v1.61.0
golangci_installed_version=$(shell golangci-lint version --format short 2>/dev/null)

lint-install:
ifneq ($(golangci_installed_version),$(golangci_version))
@echo "--> Installing golangci-lint $(golangci_version)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
endif

lint-fix:
@echo "--> Running linter"
$(MAKE) lint-install
@./scripts/lint-all.sh --fix
1 change: 1 addition & 0 deletions api/categories/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

"github.com/JulianToledano/goingecko/v3/api/categories/types"
)

Expand Down
2 changes: 0 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ type Client struct {
*trending.TrendingClient
*global.GlobalClient
*companies.CompaniesClient

url string
}

// NewDefaultClient creates a new Client using the default HTTP client and base URL
Expand Down
17 changes: 11 additions & 6 deletions api/coins/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ func (c *CoinsClient) CoinsId(ctx context.Context, id string, options ...coinsId
}

// Define option types
type localizationOption struct{ localization bool }
type tickersOption struct{ tickers bool }
type marketDataOption struct{ marketData bool }
type communityDataOption struct{ communityData bool }
type developerDataOption struct{ developerData bool }
type coinSparklineOption struct{ sparkline bool }
type (
localizationOption struct{ localization bool }
tickersOption struct{ tickers bool }
marketDataOption struct{ marketData bool }
communityDataOption struct{ communityData bool }
developerDataOption struct{ developerData bool }
coinSparklineOption struct{ sparkline bool }
)

// Implement Option interface
func (o localizationOption) Apply(v *url.Values) {
Expand All @@ -102,12 +104,15 @@ func (o tickersOption) Apply(v *url.Values) { v.Set("tickers", strconv.FormatBoo
func (o marketDataOption) Apply(v *url.Values) {
v.Set("market_data", strconv.FormatBool(o.marketData))
}

func (o communityDataOption) Apply(v *url.Values) {
v.Set("community_data", strconv.FormatBool(o.communityData))
}

func (o developerDataOption) Apply(v *url.Values) {
v.Set("developer_data", strconv.FormatBool(o.developerData))
}

func (o coinSparklineOption) Apply(v *url.Values) {
v.Set("sparkline", strconv.FormatBool(o.sparkline))
}
Expand Down
2 changes: 1 addition & 1 deletion api/coins/id_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/JulianToledano/goingecko/v3/api/internal"
"net/url"
"strconv"

"github.com/JulianToledano/goingecko/v3/api/coins/types"
"github.com/JulianToledano/goingecko/v3/api/internal"
)

// idHistoryOption is an interface that extends internal.Option to provide
Expand Down
6 changes: 4 additions & 2 deletions api/coins/id_market_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ func (c *CoinsClient) CoinsIdMarketChart(ctx context.Context, id, vsCurrency, da
return data, nil
}

type intervalIdMarketChartOptions struct{ interval string }
type precisionIdMarketChartOptions struct{ precision string }
type (
intervalIdMarketChartOptions struct{ interval string }
precisionIdMarketChartOptions struct{ precision string }
)

func (o intervalIdMarketChartOptions) Apply(v *url.Values) { v.Set("interval", o.interval) }
func (o precisionIdMarketChartOptions) Apply(v *url.Values) { v.Set("precision", o.precision) }
Expand Down
6 changes: 4 additions & 2 deletions api/coins/id_market_chart_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ func (c *CoinsClient) CoinsIdMarketChartRange(ctx context.Context, id, currency,
return data, nil
}

type intervalIdMarketChartRangeOption struct{ interval string }
type precisionIdMarketChartRangeOption struct{ precision string }
type (
intervalIdMarketChartRangeOption struct{ interval string }
precisionIdMarketChartRangeOption struct{ precision string }
)

func (o intervalIdMarketChartRangeOption) Apply(v *url.Values) { v.Set("interval", o.interval) }
func (o precisionIdMarketChartRangeOption) Apply(v *url.Values) { v.Set("precision", o.precision) }
Expand Down
13 changes: 8 additions & 5 deletions api/coins/id_tickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ func (c *CoinsClient) CoinsIdTickers(ctx context.Context, id string, options ...
}

// Define option types
type exchangeIdsOption struct{ exchangeIds string }
type includeExchangeLogoOption struct{ includeLogo bool }
type pageIdTickersOption struct{ page int64 }
type orderIdTickersOption struct{ order string }
type depthOption struct{ depth string }
type (
exchangeIdsOption struct{ exchangeIds string }
includeExchangeLogoOption struct{ includeLogo bool }
pageIdTickersOption struct{ page int64 }
orderIdTickersOption struct{ order string }
depthOption struct{ depth string }
)

// Implement Option interface
func (o exchangeIdsOption) Apply(v *url.Values) { v.Set("exchange_ids", o.exchangeIds) }

func (o includeExchangeLogoOption) Apply(v *url.Values) {
v.Set("include_exchange_logo", strconv.FormatBool(o.includeLogo))
}
Expand Down
5 changes: 2 additions & 3 deletions api/coins/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package coins

import (
"context"
"github.com/JulianToledano/goingecko/v3/api/internal"
"net/http"
"testing"

"github.com/JulianToledano/goingecko/v3/api"
"github.com/JulianToledano/goingecko/v3/api/internal"
geckohttp "github.com/JulianToledano/goingecko/v3/http"
)

Expand All @@ -23,7 +22,7 @@ func TestCoinsClient_CoinsList(t *testing.T) {
c := &CoinsClient{
internal.NewClient(
geckohttp.NewClient(geckohttp.WithHttpClient(http.DefaultClient)),
api.BaseURL,
internal.BaseURL,
),
}
got, err := c.CoinsList(context.Background(), WithIncludePlatform(true))
Expand Down
16 changes: 9 additions & 7 deletions api/coins/markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ func (c *CoinsClient) CoinsMarket(ctx context.Context, currency string, options
}

// Define option types
type idsOption struct{ ids []string }
type categoryOption struct{ category string }
type orderOption struct{ order string }
type perPageOption struct{ perPage int }
type pageOption struct{ page int }
type sparklineOption struct{ sparkline bool }
type priceChangePercentageOption struct{ intervals []string }
type (
idsOption struct{ ids []string }
categoryOption struct{ category string }
orderOption struct{ order string }
perPageOption struct{ perPage int }
pageOption struct{ page int }
sparklineOption struct{ sparkline bool }
priceChangePercentageOption struct{ intervals []string }
)

// Implement Option interface
func (o idsOption) Apply(v *url.Values) { v.Set("ids", strings.Join(o.ids, ",")) }
Expand Down
6 changes: 4 additions & 2 deletions api/coins/ohlc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ func (c *CoinsClient) CoinsOhlc(ctx context.Context, id, vsCurrency, days string
return data, nil
}

type intervalOhlcOption struct{ interval string }
type precisionOhlcOption struct{ precision string }
type (
intervalOhlcOption struct{ interval string }
precisionOhlcOption struct{ precision string }
)

func (o intervalOhlcOption) Apply(v *url.Values) { v.Set("interval", o.interval) }
func (o precisionOhlcOption) Apply(v *url.Values) { v.Set("precision", o.precision) }
Expand Down
22 changes: 0 additions & 22 deletions api/coins/types/statusUpdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,3 @@ type Project struct {
Symbol string `json:"symbol"`
Image types.Image `json:"image"`
}

/*
{
description: "Another big milestone for Fuse 🎉\r\n\r\nMajor crypto exchange MEXC Global has integrated the Fuse RPC and enabled FUSE deposits and withdrawals natively on the Fuse Network blockchain 😎\r\n\r\nRead more 👉 https://bit.ly/3rOopN4",
category: "general",
created_at: "2022-02-15T11:07:39.610Z",
user: "Robert Miller",
user_title: "Marcom Director ",
pin: false,
project: {
type: "Coin",
id: "fuse-network-token",
name: "Fuse",
symbol: "fuse",
image: {
thumb: "https://assets.coingecko.com/coins/images/10347/thumb/vUXKHEe.png?1601523640",
small: "https://assets.coingecko.com/coins/images/10347/small/vUXKHEe.png?1601523640",
large: "https://assets.coingecko.com/coins/images/10347/large/vUXKHEe.png?1601523640"
}
}
}
*/
2 changes: 1 addition & 1 deletion api/contract/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (c *ContractClient) ContractInfo(ctx context.Context, id, contractAddress s
}

var data *types.ContractAddressInfo
err = json.Unmarshal([]byte(resp), &data)
err = json.Unmarshal(resp, &data)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions api/contract/market_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/JulianToledano/goingecko/v3/api/types"
"net/url"

"github.com/JulianToledano/goingecko/v3/api/types"
)

// ContractMarketChart allows you to get the historical chart data including time in UNIX, price, market cap and 24hrs volume based on asset platform and particular token contract address.
Expand Down Expand Up @@ -45,7 +46,7 @@ func (c *ContractClient) ContractMarketChart(ctx context.Context, id, contractAd
}

var data *types.MarketChart
err = json.Unmarshal([]byte(resp), &data)
err = json.Unmarshal(resp, &data)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -98,7 +99,7 @@ func (c *ContractClient) ContractMarketChartRange(ctx context.Context, id, contr
}

var data *types.MarketChart
err = json.Unmarshal([]byte(resp), &data)
err = json.Unmarshal(resp, &data)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions api/contract/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ func WithPrecisionOption(precision string) contractOption {
return precisionContractOption{precision}
}

type intervalContractOption struct{ interval string }
type precisionContractOption struct{ precision string }
type (
intervalContractOption struct{ interval string }
precisionContractOption struct{ precision string }
)

func (o intervalContractOption) Apply(v *url.Values) {
v.Set("interval", o.interval)
}

func (o precisionContractOption) Apply(v *url.Values) {
v.Set("precision", o.precision)
}
Expand Down
5 changes: 1 addition & 4 deletions api/derivatives/derivatives.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package derivatives
import (
"context"
"encoding/json"
"fmt"

"github.com/JulianToledano/goingecko/v3/api/derivatives/types"
)
Expand All @@ -15,9 +14,7 @@ import (
// Data for open_interest and volume_24h in the endpoint responses are in USD
// Cache / Update Frequency: every 30 seconds for all the API plans
func (c *DerivativesClient) Derivatives(ctx context.Context) ([]types.Derivative, error) {

rUrl := fmt.Sprintf("%s", c.derivativesUrl())
resp, err := c.MakeReq(ctx, rUrl)
resp, err := c.MakeReq(ctx, c.derivativesUrl())
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions api/derivatives/exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,20 @@ func (c *DerivativesClient) DerivativesExchanges(ctx context.Context, options ..
return data, nil
}

type orderExchangeOption struct{ order string }
type perPageExchangeOption struct{ perPage int64 }
type pageExchangeOption struct{ page int64 }
type (
orderExchangeOption struct{ order string }
perPageExchangeOption struct{ perPage int64 }
pageExchangeOption struct{ page int64 }
)

func (o orderExchangeOption) Apply(v *url.Values) {
v.Set("order", o.order)
}

func (o perPageExchangeOption) Apply(v *url.Values) {
v.Set("per_page", strconv.FormatInt(o.perPage, 10))
}

func (o pageExchangeOption) Apply(v *url.Values) {
v.Set("page", strconv.FormatInt(o.page, 10))
}
Expand Down
6 changes: 2 additions & 4 deletions api/exchangeRates/exchangeRates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package exchangeRates
import (
"context"
"encoding/json"
"fmt"

"github.com/JulianToledano/goingecko/v3/api/exchangeRates/types"
)
Expand All @@ -18,14 +17,13 @@ import (
//
// Cache / Update Frequency: every 5 minutes for all the API plans
func (c *ExchangeRatesClient) ExchangeRates(ctx context.Context) (*types.Rates, error) {
rUrl := fmt.Sprintf("%s", c.exchangeRatesUrl())
resp, err := c.MakeReq(ctx, rUrl)
resp, err := c.MakeReq(ctx, c.exchangeRatesUrl())
if err != nil {
return nil, err
}

var data *types.Rates
err = json.Unmarshal([]byte(resp), &data)
err = json.Unmarshal(resp, &data)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions api/exchanges/by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"

"github.com/JulianToledano/goingecko/v3/api/exchanges/types"
)

Expand Down
7 changes: 5 additions & 2 deletions api/exchanges/exchanges.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ func (c *ExchangesClient) Exchanges(ctx context.Context, options ...exchangesOpt
return data, nil
}

type perPageExchangesOption struct{ perPage int64 }
type pageExchangesOption struct{ page int64 }
type (
perPageExchangesOption struct{ perPage int64 }
pageExchangesOption struct{ page int64 }
)

func (o perPageExchangesOption) Apply(v *url.Values) {
v.Set("per_page", strconv.FormatInt(o.perPage, 10))
}

func (o pageExchangesOption) Apply(v *url.Values) {
v.Set("page", strconv.FormatInt(o.page, 10))
}
Expand Down
16 changes: 11 additions & 5 deletions api/exchanges/tickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,30 @@ func (c *ExchangesClient) ExchangesIdTickers(ctx context.Context, id string) (*t
return data, nil
}

type coinIdsTickersOption struct{ ids []string }
type includeExchangeLogoTickersOption struct{ include bool }
type pageTickersOption struct{ page int64 }
type depthTickersOption struct{ depth bool }
type orderTickersOption struct{ order string }
type (
coinIdsTickersOption struct{ ids []string }
includeExchangeLogoTickersOption struct{ include bool }
pageTickersOption struct{ page int64 }
depthTickersOption struct{ depth bool }
orderTickersOption struct{ order string }
)

func (o coinIdsTickersOption) Apply(v *url.Values) {
v.Set("coin_ids", strings.Join(o.ids, ","))
}

func (o includeExchangeLogoTickersOption) Apply(v *url.Values) {
v.Set("include_exchange_logo", strconv.FormatBool(o.include))
}

func (o pageTickersOption) Apply(v *url.Values) {
v.Set("page", strconv.FormatInt(o.page, 10))
}

func (o depthTickersOption) Apply(v *url.Values) {
v.Set("depth", strconv.FormatBool(o.depth))
}

func (o orderTickersOption) Apply(v *url.Values) {
v.Set("order", o.order)
}
Expand Down
Loading

0 comments on commit a35e182

Please sign in to comment.