From bce0cd537c1fa42f318754f2abd408d0ae77d235 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Mon, 19 Aug 2024 09:24:02 -0700 Subject: [PATCH] all: fix lint --- .golangci.yml | 150 +++++++++++++++++++++++++++++++++++++++++++++++ api/api.go | 1 + api/server.go | 2 + nodes/hostd.go | 3 + nodes/manager.go | 10 ++++ nodes/renterd.go | 3 + nodes/walletd.go | 3 + 7 files changed, 172 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..050db11 --- /dev/null +++ b/.golangci.yml @@ -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 \ No newline at end of file diff --git a/api/api.go b/api/api.go index d058f90..0411ee1 100644 --- a/api/api.go +++ b/api/api.go @@ -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"` diff --git a/api/server.go b/api/server.go index 66bce20..d46fa69 100644 --- a/api/server.go +++ b/api/server.go @@ -38,6 +38,7 @@ type ( BroadcastV2BlockOutline(bo gateway.V2BlockOutline) } + // Nodes manages the set of nodes in the cluster. Nodes interface { Nodes() []nodes.Node } @@ -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, diff --git a/nodes/hostd.go b/nodes/hostd.go index b52cb89..4730cea 100644 --- a/nodes/hostd.go +++ b/nodes/hostd.go @@ -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)), diff --git a/nodes/manager.go b/nodes/manager.go index 12a8846..bb2a236 100644 --- a/nodes/manager.go +++ b/nodes/manager.go @@ -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. @@ -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"` @@ -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() @@ -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), diff --git a/nodes/renterd.go b/nodes/renterd.go index 75fd9be..2cc314b 100644 --- a/nodes/renterd.go +++ b/nodes/renterd.go @@ -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)), diff --git a/nodes/walletd.go b/nodes/walletd.go index 2c72dcb..fb683c1 100644 --- a/nodes/walletd.go +++ b/nodes/walletd.go @@ -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)),