Skip to content

Commit 75245ac

Browse files
Apply Go linter suggestions
Linting the Go code resulted in several suggestions for code improvement. This commit appies those suggestions. Changes include: - adding missing comments - imroving existing comments - renaming `DiagnosticsRegistry` type/func to `Registry` (same change conducted also in keep-core project)
1 parent d7e60d5 commit 75245ac

5 files changed

Lines changed: 21 additions & 12 deletions

File tree

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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
//
44
// Possible usage: integration nodes list into dashboard
@@ -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)