Skip to content

Commit 3f1aa45

Browse files
authored
Merge pull request #75 from keep-network/rfc-18/go-linting
Add Go linting to the client.yml workflow As part of work on RFC-18 a job linting the Go code has been added to `client.yml` workflow. Action for linting of Go code has been also added (as separate repository) as part of this work. Running the worklow with linting revealed a number of issues found by the linter ([see here](https://github.com/keep-network/keep-common/runs/2379469245?check_suite_focus=true)). All of them are also fixed as part of this PR.
2 parents b3fa31c + f1c11be commit 3f1aa45

6 files changed

Lines changed: 31 additions & 14 deletions

File tree

.github/workflows/client.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ jobs:
3838
- uses: actions/checkout@v2
3939
- uses: securego/gosec@master
4040
with:
41-
args: ./...
41+
args: ./...
42+
43+
client-lint:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
48+
- name: Lint Go
49+
uses: keep-network/golint-action@v1.0.2

pkg/chain/ethlike/block_counter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99
)
1010

11+
// BlockCounter represents a block counter.
1112
type BlockCounter struct {
1213
structMutex sync.Mutex
1314
latestBlockHeight uint64
@@ -25,6 +26,7 @@ type watcher struct {
2526
channel chan uint64
2627
}
2728

29+
// WaitForBlockHeight waits for a given block height.
2830
func (bc *BlockCounter) WaitForBlockHeight(blockNumber uint64) error {
2931
waiter, err := bc.BlockHeightWaiter(blockNumber)
3032
if err != nil {
@@ -34,6 +36,7 @@ func (bc *BlockCounter) WaitForBlockHeight(blockNumber uint64) error {
3436
return nil
3537
}
3638

39+
// BlockHeightWaiter returns a waiter for the given block.
3740
func (bc *BlockCounter) BlockHeightWaiter(
3841
blockNumber uint64,
3942
) (<-chan uint64, error) {
@@ -56,10 +59,12 @@ func (bc *BlockCounter) BlockHeightWaiter(
5659
return newWaiter, nil
5760
}
5861

62+
// CurrentBlock returns the current block.
5963
func (bc *BlockCounter) CurrentBlock() (uint64, error) {
6064
return bc.latestBlockHeight, nil
6165
}
6266

67+
// WatchBlocks watches the blocks.
6368
func (bc *BlockCounter) WatchBlocks(ctx context.Context) <-chan uint64 {
6469
watcher := &watcher{
6570
ctx: ctx,
@@ -206,6 +211,7 @@ func (bc *BlockCounter) subscribeBlocks(
206211
return nil
207212
}
208213

214+
// CreateBlockCounter creates a block counter.
209215
func CreateBlockCounter(chainReader ChainReader) (*BlockCounter, error) {
210216
ctx := context.Background()
211217

pkg/chain/ethlike/token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"strings"
99
)
1010

11+
// Token represents a token.
1112
type Token struct {
1213
*big.Int
1314
}
1415

15-
// UnmarshalText is a function used to parse an ETH-like token.
16+
// UnmarshalToken is a function used to parse an ETH-like token.
1617
func (t *Token) UnmarshalToken(text []byte, units map[string]float64) error {
1718
re := regexp.MustCompile(`^(\d+[\.]?[\d]*)[ ]?([\w]*)$`)
1819
matched := re.FindSubmatch(text)

pkg/diagnostics/diagnostics.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Package `diagnostics` provides some tools useful for gathering and
1+
// Package diagnostics provides some tools useful for gathering and
22
// exposing arbitrary diagnositcs information for external monitoring tools.
33
//
4-
// Possible usage: integration nodes list into dashboard
4+
// Possible usage: integration nodes list into dashboard.
55
package diagnostics
66

77
import (
@@ -18,21 +18,21 @@ var logger = log.Logger("keep-diagnostics")
1818

1919
// Registry performs all management of diagnostic. Specifically, it allows
2020
// to registering new diagnostics sources and exposing them through the diagnostics server.
21-
type DiagnosticsRegistry struct {
21+
type Registry struct {
2222
diagnosticsSources map[string]func() string
2323
diagnosticsMutex sync.RWMutex
2424
}
2525

2626
// NewRegistry creates a new metrics registry.
27-
func NewRegistry() *DiagnosticsRegistry {
28-
return &DiagnosticsRegistry{
27+
func NewRegistry() *Registry {
28+
return &Registry{
2929
diagnosticsSources: make(map[string]func() string),
3030
}
3131
}
3232

3333
// EnableServer enables the diagnostics server on the given port. Data will
3434
// be exposed on `/diagnostics` path in JSON format.
35-
func (r *DiagnosticsRegistry) EnableServer(port int) {
35+
func (r *Registry) EnableServer(port int) {
3636
server := &http.Server{Addr: ":" + strconv.Itoa(port)}
3737

3838
http.HandleFunc("/diagnostics", func(response http.ResponseWriter, _ *http.Request) {
@@ -48,20 +48,20 @@ func (r *DiagnosticsRegistry) EnableServer(port int) {
4848
}()
4949
}
5050

51-
// Registers diagnostics source callback with a given name.
51+
// RegisterSource registers diagnostics source callback with a given name.
5252
// Name will be used as a key and callback result as a value in JSON object
53-
// during composing diagnostics JSON.
54-
// Note: function will override existing diagnostics source on attempt
53+
// during composing diagnostics JSON.
54+
// Note: function will override existing diagnostics source on attempt
5555
// to register another one with the same name.
56-
func (r *DiagnosticsRegistry) RegisterSource(name string, source func() string) {
56+
func (r *Registry) RegisterSource(name string, source func() string) {
5757
r.diagnosticsMutex.Lock()
5858
defer r.diagnosticsMutex.Unlock()
5959

6060
r.diagnosticsSources[name] = source
6161
}
6262

6363
// Exposes all registered diagnostics sources in a single JSON document.
64-
func (r *DiagnosticsRegistry) exposeDiagnostics() string {
64+
func (r *Registry) exposeDiagnostics() string {
6565
r.diagnosticsMutex.RLock()
6666
defer r.diagnosticsMutex.RUnlock()
6767

pkg/metrics/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package `metrics` provides some tools useful for gathering and
1+
// Package metrics provides some tools useful for gathering and
22
// exposing system metrics for external monitoring tools.
33
//
44
// Currently, this package is intended to use with Prometheus but

pkg/rate/limiter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func NewLimiter(
5959
return l
6060
}
6161

62+
// AcquirePermit acquires the permit.
6263
func (l *Limiter) AcquirePermit() error {
6364
ctx, cancel := context.WithTimeout(
6465
context.Background(),
@@ -83,6 +84,7 @@ func (l *Limiter) AcquirePermit() error {
8384
return nil
8485
}
8586

87+
// ReleasePermit releases the permit.
8688
func (l *Limiter) ReleasePermit() {
8789
if l.semaphore != nil {
8890
l.semaphore.Release(1)

0 commit comments

Comments
 (0)