Skip to content

Commit

Permalink
Merge pull request #24 from bartosian/kb/hotfix/fixed-govet-issues
Browse files Browse the repository at this point in the history
Fixed govet issues in code
  • Loading branch information
bartosian authored Jan 21, 2024
2 parents c1d6d4f + ba6fdfe commit 1441622
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 68 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linters:
- dogsled
- dupl
- errcheck
- govet
- exportloopref
- exhaustive
- goconst
Expand Down
23 changes: 13 additions & 10 deletions internal/core/controllers/monitor/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,25 @@ type Builders struct {
}

type Controller struct {
lock sync.RWMutex // 8 bytes on 64-bit, keep first due to its size and to avoid false sharing
builders Builders // 8 bytes

// Pointers (8 bytes each on 64-bit systems), group together
configs map[string]config.Config // 8 bytes
gateways Gateways // 8 bytes
builders Builders // 8 bytes
hosts Hosts // 8 bytes
releases []metrics.Release // 8 bytes
configs map[string]config.Config // 8 bytes
gateways Gateways // 8 bytes
selectedConfig config.Config // size depends on the struct definition

// Strings and slices (16 bytes each on 64-bit systems), group together
network string // 16 bytes (pointer + len)
selectedTables []enums.TableType // 16 bytes (pointer + len + cap)
network string // 16 bytes (pointer + len)

// Enum and struct types, smaller than pointers, group together
selectedDashboard enums.TableType // size depends on the underlying type, typically int32 or int
selectedConfig config.Config // size depends on the struct definition
selectedDashboard enums.TableType // size depends on the underlying type, typically int32 or int
hosts Hosts // 8 bytes
releases []metrics.Release // 8 bytes

selectedTables []enums.TableType // 16 bytes (pointer + len + cap)

lock sync.RWMutex // 8 bytes on 64-bit, keep first due to its size and to avoid false sharing

}

// NewController creates a new instance of the Controller.
Expand Down
6 changes: 3 additions & 3 deletions internal/core/domain/config/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
)

type Config struct {
IPLookup struct {
AccessToken string `yaml:"access-token"`
} `yaml:"ip-lookup"`
PublicRPC []string `yaml:"public-rpc"`
FullNodes []struct {
JSONRPCAddress string `yaml:"json-rpc-address"`
Expand All @@ -23,9 +26,6 @@ type Config struct {
Validators []struct {
MetricsAddress string `yaml:"metrics-address"`
} `yaml:"validators"`
IPLookup struct {
AccessToken string `yaml:"access-token"`
} `yaml:"ip-lookup"`
}

// NewConfig reads the Suimon configuration files from the directory specified by
Expand Down
2 changes: 1 addition & 1 deletion internal/core/domain/host/addressinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const (
)

type AddressInfo struct {
Endpoint address.Endpoint
Ports map[enums.PortType]string
Endpoint address.Endpoint
}

// GetUrlRPC generates a URL for the RPC endpoint of the address.
Expand Down
6 changes: 3 additions & 3 deletions internal/core/domain/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ type Gateways struct {
type Host struct {
AddressInfo

gateways Gateways
IPInfo *ports.IPResult

TableType enums.TableType

Status enums.Status
IPInfo *ports.IPResult
Metrics metrics.Metrics

gateways Gateways
}

func NewHost(
Expand Down
27 changes: 14 additions & 13 deletions internal/core/domain/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
type (
// Transactions represents information about transactions on the Sui blockchain network.
Transactions struct {
TransactionsHistory []int
CertificatesHistory []int
TotalTransactionsBlocks int
TotalTransactionCertificates int
CertificatesCreated int
Expand All @@ -24,12 +26,11 @@ type (
TotalTransactionEffects int
TransactionsPerSecond int
TxSyncPercentage int
TransactionsHistory []int
CertificatesHistory []int
}

// Checkpoints represents information about checkpoints on the Sui blockchain network.
Checkpoints struct {
CheckpointsHistory []int
LatestCheckpoint int
HighestKnownCheckpoint int
HighestSyncedCheckpoint int
Expand All @@ -38,16 +39,15 @@ type (
CheckpointExecBacklog int
CheckpointSyncBacklog int
CheckSyncPercentage int
CheckpointsHistory []int
}

// Rounds represents information about rounds on the Sui blockchain network.
Rounds struct {
RoundsHistory []int
CurrentRound int
HighestProcessedRound int
RoundsPerSecond int
LastCommittedRound int
RoundsHistory []int
}

// Peers represents information about peers on the Sui blockchain network.
Expand All @@ -59,11 +59,11 @@ type (

// Epoch represents information about the current epoch on the Sui blockchain network.
Epoch struct {
CurrentEpoch int
EpochStartTimeUTC string
EpochTotalDuration int
EpochDurationHHMM string
DurationTillEpochEndHHMM string
CurrentEpoch int
EpochTotalDuration int
EpochPercentage int
TimeTillNextEpoch int64
}
Expand All @@ -86,23 +86,24 @@ type (

// Metrics represents various metrics about the Sui blockchain network.
Metrics struct {
Updated bool

SystemState SuiSystemState
ValidatorsApyParsed ValidatorsApyParsed

Uptime string
Version string
Commit string

Transactions
Checkpoints
SystemState SuiSystemState

Epoch
Protocol
Rounds
Peers
Epoch

Transactions
Checkpoints
GasPrice
Peers
Errors
Updated bool
}
)

Expand Down
4 changes: 2 additions & 2 deletions internal/core/domain/metrics/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type Release struct {
TagName string `json:"tag_name"`
CommitHash string `json:"target_commitish"`
Name string `json:"name"`
Draft bool `json:"draft"`
PreRelease bool `json:"prerelease"`
PublishedAt string `json:"published_at"`
CreatedAt string `json:"created_at"`
URL string `json:"html_url"`
Author struct {
Login string `json:"login"`
} `json:"author"`
Draft bool `json:"draft"`
PreRelease bool `json:"prerelease"`
}

// getReleases fetches releases for a given repo and filters them by network name
Expand Down
12 changes: 6 additions & 6 deletions internal/core/domain/metrics/suisystemstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const validatorsQuorum = 6667
type (
// SuiSystemState represents the current state of the Sui blockchain system.
SuiSystemState struct {
AddressToValidator AddressToValidator
Epoch string `json:"epoch"`
ProtocolVersion string `json:"protocolVersion"`
SystemStateVersion string `json:"systemStateVersion"`
StorageFundTotalObjectStorageRebates string `json:"storageFundTotalObjectStorageRebates"`
StorageFundNonRefundableBalance string `json:"storageFundNonRefundableBalance"`
ReferenceGasPrice string `json:"referenceGasPrice"`
SafeMode bool `json:"safeMode"`
SafeModeStorageRewards string `json:"safeModeStorageRewards"`
SafeModeComputationRewards string `json:"safeModeComputationRewards"`
SafeModeStorageRebates string `json:"safeModeStorageRebates"`
Expand All @@ -35,23 +35,23 @@ type (
StakeSubsidyDistributionCounter string `json:"stakeSubsidyDistributionCounter"`
StakeSubsidyCurrentDistributionAmount string `json:"stakeSubsidyCurrentDistributionAmount"`
StakeSubsidyPeriodLength string `json:"stakeSubsidyPeriodLength"`
StakeSubsidyDecreaseRate int `json:"stakeSubsidyDecreaseRate"`
TotalStake string `json:"totalStake"`
ActiveValidators Validators `json:"activeValidators"`
PendingActiveValidatorsID string `json:"pendingActiveValidatorsId"`
PendingActiveValidatorsSize string `json:"pendingActiveValidatorsSize"`
PendingRemovals []interface{} `json:"pendingRemovals"`
StakingPoolMappingsID string `json:"stakingPoolMappingsId"`
StakingPoolMappingsSize string `json:"stakingPoolMappingsSize"`
InactivePoolsID string `json:"inactivePoolsId"`
InactivePoolsSize string `json:"inactivePoolsSize"`
ValidatorCandidatesID string `json:"validatorCandidatesId"`
ValidatorCandidatesSize string `json:"validatorCandidatesSize"`
ActiveValidators Validators `json:"activeValidators"`
PendingRemovals []interface{} `json:"pendingRemovals"`
AtRiskValidators [][]interface{} `json:"atRiskValidators"`
ValidatorReportRecords [][]interface{} `json:"validatorReportRecords"`
AddressToValidator AddressToValidator
ValidatorsAtRiskParsed ValidatorsAtRisk
ValidatorReportsParsed ValidatorsReports
StakeSubsidyDecreaseRate int `json:"stakeSubsidyDecreaseRate"`
SafeMode bool `json:"safeMode"`
}

// ValidatorsApy represents the APYs of validators.
Expand All @@ -71,8 +71,8 @@ type (
// ValidatorReport represents validator reporters
ValidatorReport struct {
Name string
SlashingPercentage float64
Reporters []ValidatorReporter
SlashingPercentage float64
}

// ValidatorReporter contains information about a validator reporter
Expand Down
2 changes: 1 addition & 1 deletion internal/core/domain/service/dashboardbuilder/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (

type Builder struct {
ctx context.Context
tableType enums.TableType
cliGateway *cligw.Gateway
terminal *termbox.Terminal
dashboard *container.Container
host *domainhost.Host
cells dashboards.Cells
quitter func(k *terminalapi.Keyboard)
tableType enums.TableType
}

// NewBuilder creates a new Builder instance with the provided CLI gateway.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type Cells map[enums.ColumnName]*Cell

// Cell is a struct that represents a single cell in a dashboard grid. It contains a widget and a list of options.
type Cell struct {
LastUpdatedAt time.Time
Widget widgetapi.Widget
Options []container.Option
LastUpdatedAt time.Time
}

// NewCell is a function that creates a new Cell struct given a cellName and a widget. It returns a pointer to the new Cell and an error (if any).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type RowsConfig []RowConfig
// RowConfig is a type that represents the configuration for a single row in a grid.
// It contains a height and a list of column names that should be included in the row.
type RowConfig struct {
Height int
Columns []enums.ColumnName
Height int
}

// Rows is a type that represents a set of grid rows, each of which is an element in the grid.
Expand Down
6 changes: 3 additions & 3 deletions internal/core/domain/service/tablebuilder/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const slashingPct50 = 50
const slashingPct100 = 50

type Builder struct {
writer table.Writer
cliGateway *cligw.Gateway
config *tables.TableConfig
tableType enums.TableType
hosts []host.Host
Releases []metrics.Release
cliGateway *cligw.Gateway
writer table.Writer
config *tables.TableConfig
}

// NewBuilder creates a new instance of the table builder, using the CLI gateway
Expand Down
4 changes: 2 additions & 2 deletions internal/core/domain/service/tablebuilder/tables/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ type SortConfig []table.SortBy

// TableConfig represents the overall configuration for a table.
type TableConfig struct {
Name string // The name of the table
Style table.Style // The style of the table
Columns ColumnsConfig // Configuration for the table's columns
Name string // The name of the table
Rows RowsConfig // Configuration for the table's rows
Style table.Style // The style of the table
ColumnsCount int // The total number of columns in the table
RowsCount int // The total number of rows in the table
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/domain/service/tablebuilder/tables/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type (
ColumnValues map[enums.ColumnName]any

Column struct {
Values []any
Config *table.ColumnConfig
Values []any
}
)

Expand Down
6 changes: 3 additions & 3 deletions internal/core/gateways/cligw/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (gateway *Gateway) ErrorfWithOpts(msg string, opts MsgOpts, vars ...interfa
}

func (Gateway) ErrorWithOpts(msg string, opts MsgOpts) {
var icon string
var newIcon string

for icon, i := errorIcon, opts.Indent; i > 0; i-- {
icon = fmt.Sprintf(" %s", icon)
newIcon = fmt.Sprintf(" %s", icon)
}

formattedIcon := iconErrColor.Sprint(icon)
formattedIcon := iconErrColor.Sprint(newIcon)
formattedMsg := messageErrColor.Sprint(msg)

result := fmt.Sprintf("%s %s", formattedIcon, formattedMsg)
Expand Down
6 changes: 3 additions & 3 deletions internal/core/gateways/cligw/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func (gateway *Gateway) InfoWithOpts(label, value string, opts MsgOpts) {
}

func (Gateway) infoLabel(label string, indent int) string {
var icon string
var newIcon string

for icon, i := infoIcon, indent; i > 0; i-- {
icon = fmt.Sprintf(" %s", icon)
newIcon = fmt.Sprintf(" %s", icon)
}

bang := iconInfoColor.Sprint(icon)
bang := iconInfoColor.Sprint(newIcon)
formattedLabel := messageInfoColor.Sprint(label)

return fmt.Sprintf("%s %s", bang, formattedLabel)
Expand Down
2 changes: 1 addition & 1 deletion internal/core/gateways/cligw/selectchoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cligw
type (
SelectChoiceList []SelectChoice
SelectChoice struct {
Data any
Label string
Value string
Data any
}
)

Expand Down
6 changes: 3 additions & 3 deletions internal/core/gateways/cligw/warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (gateway *Gateway) WarnfWithOpts(msg string, opts MsgOpts, vars ...interfac
}

func (Gateway) WarnWithOpts(msg string, opts MsgOpts) {
var icon string
var newIcon string

for icon, i := warnIcon, opts.Indent; i > 0; i-- {
icon = fmt.Sprintf(" %s", icon)
newIcon = fmt.Sprintf(" %s", icon)
}

formattedIcon := iconWarnColor.Sprint(icon)
formattedIcon := iconWarnColor.Sprint(newIcon)
formattedMsg := messageWarnColor.Sprint(msg)

result := fmt.Sprintf("%s %s", formattedIcon, formattedMsg)
Expand Down
2 changes: 1 addition & 1 deletion internal/core/gateways/geogw/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const (

type Gateway struct {
ctx context.Context
accessToken string
client *ipinfo.Client
cliGateway *cligw.Gateway
accessToken string
}

func NewGateway(cliGW *cligw.Gateway, accessToken string) ports.GeoGateway {
Expand Down
Loading

0 comments on commit 1441622

Please sign in to comment.