From a35102a684410bf50f32d691990ac30c59e61afa Mon Sep 17 00:00:00 2001 From: Shahbaz Nazir Date: Wed, 6 Dec 2023 10:57:50 +0100 Subject: [PATCH] fix lint --- config.yaml | 2 +- pkg/collector/collector.go | 3 +++ pkg/collector/ibc_collector.go | 3 +-- pkg/collector/wallet_balance_collector.go | 13 +++++-------- pkg/config/config.go | 16 ++++++++++------ 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/config.yaml b/config.yaml index a9ce3db..f9b2e14 100644 --- a/config.yaml +++ b/config.yaml @@ -88,4 +88,4 @@ accounts: # PhiLabs - address: archway1ktka5q3cnsy3ar7qwj2huzz6qj9q4ys7h74l9y chainName: archway - denom: aarch \ No newline at end of file + denom: aarch diff --git a/pkg/collector/collector.go b/pkg/collector/collector.go index 7b55480..09d58a7 100644 --- a/pkg/collector/collector.go +++ b/pkg/collector/collector.go @@ -1,6 +1,7 @@ package collector import ( + "context" "regexp" "strings" @@ -12,6 +13,8 @@ const ( errorStatus = "error" ) +var ctx = context.Background() + func getDiscordIDs(ops []config.Operator) string { var ids []string diff --git a/pkg/collector/ibc_collector.go b/pkg/collector/ibc_collector.go index 564280f..efabaa4 100644 --- a/pkg/collector/ibc_collector.go +++ b/pkg/collector/ibc_collector.go @@ -1,7 +1,6 @@ package collector import ( - "context" "fmt" "reflect" "sync" @@ -67,7 +66,7 @@ func (cc IBCCollector) Collect(ch chan<- prometheus.Metric) { fmt.Sprintf("%s, %s", clientExpiryMetricName, channelStuckPacketsMetricName), ), ) - ctx := context.Background() + var wg sync.WaitGroup for _, p := range cc.Paths { diff --git a/pkg/collector/wallet_balance_collector.go b/pkg/collector/wallet_balance_collector.go index ea18909..d91fb09 100644 --- a/pkg/collector/wallet_balance_collector.go +++ b/pkg/collector/wallet_balance_collector.go @@ -1,7 +1,6 @@ package collector import ( - "context" "math/big" "sync" @@ -16,12 +15,10 @@ const ( walletBalanceMetricName = "cosmos_wallet_balance" ) -var ( - walletBalance = prometheus.NewDesc( - walletBalanceMetricName, - "Returns wallet balance for an address on a chain.", - []string{"account", "chain_id", "denom", "status"}, nil, - ) +var walletBalance = prometheus.NewDesc( + walletBalanceMetricName, + "Returns wallet balance for an address on a chain.", + []string{"account", "chain_id", "denom", "status"}, nil, ) type WalletBalanceCollector struct { @@ -35,8 +32,8 @@ func (wb WalletBalanceCollector) Describe(ch chan<- *prometheus.Desc) { func (wb WalletBalanceCollector) Collect(ch chan<- prometheus.Metric) { log.Debug("Start collecting", zap.String("metric", walletBalanceMetricName)) + var wg sync.WaitGroup - ctx := context.Background() for _, a := range wb.Accounts { wg.Add(1) diff --git a/pkg/config/config.go b/pkg/config/config.go index a261497..1663239 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -21,8 +21,10 @@ import ( const ibcPathSuffix = ".json" -var ErrGitHubClient = errors.New("GitHub client not provided") -var ErrMissingRPCConfigMsg = "missing RPC config for chain: %s" +var ( + ErrGitHubClient = errors.New("GitHub client not provided") + ErrMissingRPCConfigMsg = "missing RPC config for chain: %s" +) type Account struct { Address string `yaml:"address" validate:"required"` @@ -229,10 +231,10 @@ func (c *Config) Validate() error { // register custom validation for http url as expected by go relayer i.e. // http_url must have port defined. // https://github.com/cosmos/relayer/blob/259b1278264180a2aefc2085f1b55753849c4815/cregistry/chain_info.go#L115 - validate.RegisterValidation("has_port", func(fl validator.FieldLevel) bool { + err := validate.RegisterValidation("has_port", func(fl validator.FieldLevel) bool { val := fl.Field().String() - val_arr := strings.Split(val, ":") - port := val_arr[len(val_arr)-1] + valArr := strings.Split(val, ":") + port := valArr[len(valArr)-1] // Port must be a iny <= 65535. if portNum, err := strconv.ParseInt( @@ -242,11 +244,13 @@ func (c *Config) Validate() error { } return true }) + if err != nil { + return err + } // validate top level fields if err := validate.Struct(c); err != nil { return err - } // validate RPCs