Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci-lint #26

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
run: echo ${{ steps.docker_build.outputs.digest }}

- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: ncipollo/release-action@v1
with:
allowUpdates: true
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Lint

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:

permissions:
contents: read
repository-projects: read
packages: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
golangci-lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.56.0
args: --timeout 10m --tests=false --out-format=github-actions
skip-pkg-cache: true
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
name: Tests

on:
push:
branches:
- main
- master
pull_request:
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:

permissions:
contents: read
repository-projects: read
packages: read

concurrency:
group: ci-${{ github.ref }}-tests
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down
16 changes: 6 additions & 10 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,13 @@ func GetLogLevel(lvl string) zapcore.Level {
}
}

func GetDenomList(chain string, chainList map[string][]string) []string {
var found bool

func GetDenomList(chain string, chainList map[string][]string) ([]string, error) {
for k, v := range chainList {
if k == chain {
found = true
return v
return v, nil
}
}
if !found {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", "chain("+chain+") denom not supported"))
}
return []string{}
return []string{}, fmt.Errorf("chain(%s) denom not supported", chain)
}

func GetChainList() map[string][]string {
Expand All @@ -171,7 +165,9 @@ func GetChainList() map[string][]string {
byteValue, _ := io.ReadAll(jsonFile)

var chains []Chain
json.Unmarshal(byteValue, &chains)
if err := json.Unmarshal(byteValue, &chains); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

chainList := make(map[string][]string)
for _, chain := range chains {
Expand Down
5 changes: 4 additions & 1 deletion exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func Start(config *config.Config, port string, logger *zap.Logger, restService c
}

func CollectMetrics(cfg *config.Config, log *zap.Logger, restService controllers.RestServices, rpcService controllers.RpcServices) {
denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

registerGauges(denomList)
counterVecs := registerLabels()
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func main() {
go dashboard.StartDashboard()
}

denomList := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
denomList, err := config.GetDenomList(cfg.Chain.Name, cfg.ChainList)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// start the data fetcher in a separate thread
fetcher.Start(&cfg, restServicesController, rpcServicesController, denomList, logger)
Expand Down
32 changes: 24 additions & 8 deletions services/akash/akash.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &deployments)
if err := json.Unmarshal(res, &deployments); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// get total deployments count
totalDeploymentsCount, err := strconv.Atoi(deployments.Pagination.Total)
Expand All @@ -49,7 +51,9 @@ func (as *AkashService) GetAkashDeployments(cfg config.Config, data *types.Async
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(resActive, &activeDeployments)
if err := json.Unmarshal(resActive, &activeDeployments); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

activeDeploymentsCount, err := strconv.Atoi(activeDeployments.Pagination.Total)
if err != nil {
Expand All @@ -74,7 +78,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &providers)
if err := json.Unmarshal(res, &providers); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// handle pagination
nextKey := providers.Pagination.NextKey
Expand All @@ -84,7 +90,9 @@ func (as *AkashService) GetAkashProviders(cfg config.Config, data *types.AsyncDa
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
var nextPage akash.ProvidersResponse
json.Unmarshal(res, &nextPage)
if err := json.Unmarshal(res, &nextPage); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// append to the response
providers.Providers = append(providers.Providers, nextPage.Providers...)
Expand Down Expand Up @@ -175,7 +183,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide
if err != nil {
return fmt.Errorf("error querying auditors for provider owner: %w", err)
}
json.Unmarshal(res, &auditors)
if err := json.Unmarshal(res, &auditors); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// handle pagination
nextKey := auditors.Pagination.NextKey
Expand All @@ -185,7 +195,9 @@ func (as *AkashService) IndexAuditorForProviderOwners(cfg config.Config, provide
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
var nextPage akash.AuditorsResponse
json.Unmarshal(res, &nextPage)
if err := json.Unmarshal(res, &nextPage); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// append to the response
auditors.Providers = append(auditors.Providers, nextPage.Providers...)
Expand Down Expand Up @@ -259,7 +271,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi
if err != nil {
return fmt.Errorf("error querying deployments for provider owner: %w", err)
}
json.Unmarshal(res, &deployments)
if err := json.Unmarshal(res, &deployments); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// handle pagination
nextKey := deployments.Pagination.NextKey
Expand All @@ -269,7 +283,9 @@ func (as *AkashService) IndexDeploymentForProviderOwner(cfg config.Config, provi
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
var nextPage akash.DeploymentsResponse
json.Unmarshal(res, &nextPage)
if err := json.Unmarshal(res, &nextPage); err != nil {
zap.L().Info("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

// append to the response
deployments.Deployments = append(deployments.Deployments, nextPage.Deployments...)
Expand Down
8 changes: 6 additions & 2 deletions services/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (bs *BankService) GetBalanceInfo(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &b)
if err := json.Unmarshal(res, &b); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if strings.Contains(string(res), "not found") {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
Expand All @@ -61,7 +63,9 @@ func (bs *BankService) GetRewardsCommissionInfo(cfg config.Config, rd *types.RES
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &rc)
if err := json.Unmarshal(res, &rc); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if strings.Contains(string(res), "not found") {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
Expand Down
8 changes: 6 additions & 2 deletions services/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func (bs *BlockService) GetInfo(cfg config.Config) types.Blocks {
if err != nil {
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &bs.Block)
if err := json.Unmarshal(res, &bs.Block); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if strings.Contains(string(res), "not found") {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
Expand All @@ -56,7 +58,9 @@ func (bs *BlockService) GetLastBlockTimestamp(cfg config.Config, currentHeight i
if err != nil {
zap.L().Fatal("Connection to REST failed", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &lastBlock)
if err := json.Unmarshal(res, &lastBlock); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if strings.Contains(string(res), "not found") {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
Expand Down
4 changes: 3 additions & 1 deletion services/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (css *ConsensusService) GetConsensusDump(cfg config.Config, rpc *types.RPCD
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &cs)
if err := json.Unmarshal(res, &cs); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

conspubMonikerMap := rest.GetConspubMonikerMapWrapper()
// cs.Result.Validatorset.Validators is already sorted based on voting power
Expand Down
6 changes: 4 additions & 2 deletions services/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func (ds *DelegationService) GetInfo(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &delInfo)
if err := json.Unmarshal(res, &delInfo); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if strings.Contains(string(res), "not found") {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", string(res)))
} else if strings.Contains(string(res), "error:") || strings.Contains(string(res), "error\\\":") {
Expand All @@ -45,7 +47,7 @@ func (ds *DelegationService) GetInfo(cfg config.Config, rd *types.RESTData) {
func() {
defer func() {
if r := recover(); r != nil {
// precommit failure validator
zap.L().Error("", zap.Bool("Success", false), zap.String("err", "failed to get delegation info"))
}
}()
delRes[value.Delegation.DelegatorAddr] = []string{value.Balance.Amount}
Expand Down
8 changes: 6 additions & 2 deletions services/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (rs *GovService) GetInfo(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &g)
if err := json.Unmarshal(res, &g); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

totalProposals := g.Proposals
for _, value := range totalProposals {
Expand All @@ -60,7 +62,9 @@ func (rs *GovService) GetInfo(cfg config.Config, rd *types.RESTData) {
log.Info().Msgf("Error getting vote info: %v", err)
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &voteInfo)
if err := json.Unmarshal(res, &voteInfo); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
if voteInfo.Vote.Options[0].Option != "" {
inVotingVoted++
} else {
Expand Down
28 changes: 21 additions & 7 deletions services/gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func GetUmeePrice(rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &p)
if err := json.Unmarshal(res, &p); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

rd.GravityInfo.UMEEPrice = p.UMEEPrice
}
Expand All @@ -45,7 +47,9 @@ func (gs *GravityService) GetBatchFees(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &b)
if err := json.Unmarshal(res, &b); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

for _, bf := range b.BatchFees {
b.Fees += utils.StringToFloat64(bf.TotalFees)
Expand All @@ -67,7 +71,9 @@ func (gs *GravityService) GetBatchesFees(cfg config.Config, rd *types.RESTData)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &b)
if err := json.Unmarshal(res, &b); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

for _, batch := range b.Batches {
for _, tx := range batch.Transactions {
Expand All @@ -92,7 +98,9 @@ func (gs *GravityService) GetBridgeFees(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &p)
if err := json.Unmarshal(res, &p); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

rd.GravityInfo.ETHPrice = p.ETHPrice
GetUmeePrice(rd)
Expand All @@ -112,7 +120,9 @@ func (gs *GravityService) GetBridgeParams(cfg config.Config, rd *types.RESTData)
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &params)
if err := json.Unmarshal(res, &params); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

rd.GravityInfo.BridgeParams = params.BridgeParams

Expand All @@ -135,7 +145,9 @@ func (gs *GravityService) GetOracleEventNonce(cfg config.Config, rd *types.RESTD
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &evt)
if err := json.Unmarshal(res, &evt); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

rd.GravityInfo.EventNonce = evt.EventNonce
}
Expand All @@ -153,7 +165,9 @@ func (gs *GravityService) GetValSet(cfg config.Config, rd *types.RESTData) {
if err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}
json.Unmarshal(res, &vs)
if err := json.Unmarshal(res, &vs); err != nil {
zap.L().Fatal("", zap.Bool("Success", false), zap.String("err", err.Error()))
}

for _, member := range vs.ValSet.Members {
vsResult[member.ETHAddr] = member.Power
Expand Down
Loading
Loading