Skip to content

Commit

Permalink
all: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Aug 19, 2024
1 parent 41bffe7 commit bce0cd5
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 0 deletions.
150 changes: 150 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Based off of the example file at https://github.com/golangci/golangci-lint

# options for analysis running
run:
# default concurrency is a available CPU number
concurrency: 4

# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 600s

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# include test files or not, default is true
tests: true

# list of build tags, all linters use it. Default is empty list.
build-tags: []

# output configuration options
output:
# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

# all available settings of specific linters
linters-settings:
## Enabled linters:
govet:
# report about shadowed variables
disable-all: false

tagliatelle:
case:
rules:
json: goCamel
yaml: goCamel


gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.
enabled-tags:
- diagnostic
- style
disabled-checks:
# diagnostic
- appendAssign
- commentedOutCode
- uncheckedInlineErr
# style
- httpNoBody
- exitAfterDefer
- ifElseChain
- importShadow
- initClause
- nestingReduce
- octalLiteral
- paramTypeCombine
- ptrToRefParam
- stringsCompare
- tooManyResultsChecker
- typeDefFirst
- typeUnparen
- unlabelStmt
- unnamedResult
- whyNoLint
revive:
ignore-generated-header: true
rules:
- name: blank-imports
disabled: false
- name: bool-literal-in-expr
disabled: false
- name: confusing-naming
disabled: false
- name: confusing-results
disabled: false
- name: constant-logical-expr
disabled: false
- name: context-as-argument
disabled: false
- name: exported
disabled: false
- name: errorf
disabled: false
- name: if-return
disabled: false
- name: indent-error-flow
disabled: true
- name: increment-decrement
disabled: false
- name: modifies-value-receiver
disabled: true
- name: optimize-operands-order
disabled: false
- name: range-val-in-closure
disabled: false
- name: struct-tag
disabled: false
- name: superfluous-else
disabled: false
- name: time-equal
disabled: false
- name: unexported-naming
disabled: false
- name: unexported-return
disabled: false
- name: unnecessary-stmt
disabled: false
- name: unreachable-code
disabled: false
- name: package-comments
disabled: true

linters:
disable-all: true
fast: false
enable:
- tagliatelle
- gocritic
- gofmt
- revive
- govet
- misspell
- typecheck
- whitespace

issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude: []

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: false
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type MineRequest struct {
Address types.Address `json:"address"`
}

// A ProxyResponse is the response for a proxied API request from a node.
type ProxyResponse struct {
NodeID nodes.NodeID `json:"nodeID"`
StatusCode int `json:"statusCode"`
Expand Down
2 changes: 2 additions & 0 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type (
BroadcastV2BlockOutline(bo gateway.V2BlockOutline)
}

// Nodes manages the set of nodes in the cluster.
Nodes interface {
Nodes() []nodes.Node
}
Expand Down Expand Up @@ -185,6 +186,7 @@ func (srv *server) proxyNodeAPI(jc jape.Context) {
jc.Encode(responses)
}

// Handler returns an http.Handler that serves the API.
func Handler(cm ChainManager, s Syncer, n Nodes, log *zap.Logger) http.Handler {
srv := &server{
chain: cm,
Expand Down
3 changes: 3 additions & 0 deletions nodes/hostd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
"lukechampine.com/frand"
)

// Hostd starts a new hostd node. It listens on random ports and registers
// itself with the provided Manager. This function blocks until the context is
// canceled. All resources will be cleaned up before the function returns.
func Hostd(ctx context.Context, baseDir string, pk types.PrivateKey, cm *chain.Manager, s *syncer.Syncer, nm *Manager, log *zap.Logger) error {
node := Node{
ID: NodeID(frand.Bytes(8)),
Expand Down
10 changes: 10 additions & 0 deletions nodes/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import (
"go.sia.tech/core/types"
)

// Types for the supported nodes.
const (
NodeTypeRenterd = NodeType("renterd")
NodeTypeHostd = NodeType("hostd")
NodeTypeWalletd = NodeType("walletd")
)

// A NodeType represents the type of a node.
type NodeType string

// A NodeID is a unique identifier for a node.
type NodeID [8]byte

// String returns the hexadecimal representation of the NodeID.
Expand All @@ -40,6 +43,7 @@ func (id *NodeID) UnmarshalText(text []byte) error {
return err
}

// A Node represents a running node in the cluster.
type Node struct {
ID NodeID `json:"id"`
Type NodeType `json:"type"`
Expand All @@ -50,23 +54,28 @@ type Node struct {
WalletAddress types.Address `json:"walletAddress"`
}

// A Manager manages a set of nodes in the cluster.
type Manager struct {
mu sync.Mutex
nodes map[NodeID]Node
}

// Put adds a node to the manager.
func (m *Manager) Put(node Node) {
m.mu.Lock()
m.nodes[node.ID] = node
m.mu.Unlock()
}

// Delete removes a node from the manager.
// The node is not stopped.
func (m *Manager) Delete(id NodeID) {
m.mu.Lock()
delete(m.nodes, id)
m.mu.Unlock()
}

// Nodes returns a slice of all running nodes in the manager.
func (m *Manager) Nodes() []Node {
m.mu.Lock()
defer m.mu.Unlock()
Expand All @@ -85,6 +94,7 @@ func createNodeDir(baseDir string, id NodeID) (dir string, err error) {
return
}

// NewManager creates a new node manager.
func NewManager() *Manager {
return &Manager{
nodes: make(map[NodeID]Node),
Expand Down
3 changes: 3 additions & 0 deletions nodes/renterd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (
"lukechampine.com/frand"
)

// Renterd starts a new renterd node. It listens on random ports and registers
// itself with the provided Manager. This function blocks until the context is
// canceled. All resources will be cleaned up before the function returns.
func Renterd(ctx context.Context, baseDir string, pk types.PrivateKey, cm *chain.Manager, s *syncer.Syncer, nm *Manager, log *zap.Logger) error {
node := Node{
ID: NodeID(frand.Bytes(8)),
Expand Down
3 changes: 3 additions & 0 deletions nodes/walletd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"lukechampine.com/frand"
)

// Walletd starts a new walletd node. It listens on random ports and registers
// itself with the provided Manager. This function blocks until the context is
// canceled. All resources will be cleaned up before the function returns.
func Walletd(ctx context.Context, baseDir string, cm *chain.Manager, s *syncer.Syncer, nm *Manager, log *zap.Logger) error {
node := Node{
ID: NodeID(frand.Bytes(8)),
Expand Down

0 comments on commit bce0cd5

Please sign in to comment.