modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)

* modernise: Run new gopls modernise tool against codebase

* Address shazbert's nits

* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling

* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS

* refactor: Various slice usage improvements and rename TODO

* tranches: Revert deleteByID changes due to performance decrease

Shazbert was a F1 driver in a past lifetime 🏎️

* tranches: Simply retrieve copy

Thanks to shazbert

* documentation: Sort contributors list by contributions

* tranches: Remove deadcode in deleteByID
This commit is contained in:
Adrian Gallagher
2025-03-21 09:17:10 +11:00
committed by GitHub
parent d857d704e3
commit 4651af5767
223 changed files with 1504 additions and 1752 deletions

14
common/cache/cache.go vendored
View File

@@ -8,35 +8,35 @@ func New(capacity uint64) *LRUCache {
}
// Add new entry to Cache return true if entry removed
func (l *LRUCache) Add(k, v interface{}) {
func (l *LRUCache) Add(k, v any) {
l.m.Lock()
l.lru.Add(k, v)
l.m.Unlock()
}
// Get looks up a key's value from the cache.
func (l *LRUCache) Get(key interface{}) (value interface{}) {
func (l *LRUCache) Get(key any) (value any) {
l.m.Lock()
defer l.m.Unlock()
return l.lru.Get(key)
}
// GetOldest looks up old key's value from the cache.
func (l *LRUCache) getOldest() (key, value interface{}) {
func (l *LRUCache) getOldest() (key, value any) {
l.m.Lock()
defer l.m.Unlock()
return l.lru.getOldest()
}
// getNewest looks up a key's value from the cache.
func (l *LRUCache) getNewest() (key, value interface{}) {
func (l *LRUCache) getNewest() (key, value any) {
l.m.Lock()
defer l.m.Unlock()
return l.lru.getNewest()
}
// ContainsOrAdd checks if cache contains key if not adds to cache
func (l *LRUCache) ContainsOrAdd(key, value interface{}) bool {
func (l *LRUCache) ContainsOrAdd(key, value any) bool {
l.m.Lock()
defer l.m.Unlock()
if l.lru.Contains(key) {
@@ -47,14 +47,14 @@ func (l *LRUCache) ContainsOrAdd(key, value interface{}) bool {
}
// Contains checks if cache contains key
func (l *LRUCache) Contains(key interface{}) bool {
func (l *LRUCache) Contains(key any) bool {
l.m.Lock()
defer l.m.Unlock()
return l.lru.Contains(key)
}
// Remove entry from cache
func (l *LRUCache) Remove(key interface{}) bool {
func (l *LRUCache) Remove(key any) bool {
l.m.Lock()
defer l.m.Unlock()
return l.lru.Remove(key)

View File

@@ -15,11 +15,11 @@ type LRUCache struct {
type LRU struct {
Cap uint64
l *list.List
items map[interface{}]*list.Element
items map[any]*list.Element
}
// item holds key/value for the cache
type item struct {
key interface{}
value interface{}
key any
value any
}

14
common/cache/lru.go vendored
View File

@@ -16,12 +16,12 @@ func NewLRUCache(capacity uint64) *LRU {
return &LRU{
Cap: capacity,
l: list.New(),
items: make(map[interface{}]*list.Element),
items: make(map[any]*list.Element),
}
}
// Add adds a value to the cache
func (l *LRU) Add(key, value interface{}) {
func (l *LRU) Add(key, value any) {
if f, o := l.items[key]; o {
l.l.MoveToFront(f)
if v, ok := f.Value.(*item); ok {
@@ -39,7 +39,7 @@ func (l *LRU) Add(key, value interface{}) {
}
// Get returns keys value from cache if found
func (l *LRU) Get(key interface{}) interface{} {
func (l *LRU) Get(key any) any {
if i, f := l.items[key]; f {
l.l.MoveToFront(i)
if v, ok := i.Value.(*item); ok {
@@ -50,7 +50,7 @@ func (l *LRU) Get(key interface{}) interface{} {
}
// GetOldest returns the oldest entry
func (l *LRU) getOldest() (key, value interface{}) {
func (l *LRU) getOldest() (key, value any) {
if x := l.l.Back(); x != nil {
if v, ok := x.Value.(*item); ok {
return v.key, v.value
@@ -60,7 +60,7 @@ func (l *LRU) getOldest() (key, value interface{}) {
}
// GetNewest returns the newest entry
func (l *LRU) getNewest() (key, value interface{}) {
func (l *LRU) getNewest() (key, value any) {
if x := l.l.Front(); x != nil {
if v, ok := x.Value.(*item); ok {
return v.key, v.value
@@ -70,13 +70,13 @@ func (l *LRU) getNewest() (key, value interface{}) {
}
// Contains check if key is in cache this does not update LRU
func (l *LRU) Contains(key interface{}) (f bool) {
func (l *LRU) Contains(key any) (f bool) {
_, f = l.items[key]
return
}
// Remove removes key from the cache, if the key was removed.
func (l *LRU) Remove(key interface{}) bool {
func (l *LRU) Remove(key any) bool {
if i, f := l.items[key]; f {
l.removeElement(i)
return true

View File

@@ -594,7 +594,7 @@ func GenerateRandomString(length uint, characters ...string) (string, error) {
// GetTypeAssertError returns additional information for when an assertion failure
// occurs.
// fieldDescription is an optional way to return what the affected field was for
func GetTypeAssertError(required string, received interface{}, fieldDescription ...string) error {
func GetTypeAssertError(required string, received any, fieldDescription ...string) error {
var description string
if len(fieldDescription) > 0 {
description = " for: " + strings.Join(fieldDescription, ", ")

View File

@@ -11,7 +11,7 @@ import (
)
// FloatFromString format
func FloatFromString(raw interface{}) (float64, error) {
func FloatFromString(raw any) (float64, error) {
str, ok := raw.(string)
if !ok {
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
@@ -24,7 +24,7 @@ func FloatFromString(raw interface{}) (float64, error) {
}
// IntFromString format
func IntFromString(raw interface{}) (int, error) {
func IntFromString(raw any) (int, error) {
str, ok := raw.(string)
if !ok {
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
@@ -37,7 +37,7 @@ func IntFromString(raw interface{}) (int, error) {
}
// Int64FromString format
func Int64FromString(raw interface{}) (int64, error) {
func Int64FromString(raw any) (int64, error) {
str, ok := raw.(string)
if !ok {
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
@@ -50,7 +50,7 @@ func Int64FromString(raw interface{}) (int64, error) {
}
// TimeFromUnixTimestampFloat format
func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
func TimeFromUnixTimestampFloat(raw any) (time.Time, error) {
ts, ok := raw.(float64)
if !ok {
return time.Time{}, fmt.Errorf("unable to parse, value not float64: %T", raw)
@@ -167,7 +167,7 @@ func numberToHumanFriendlyString(str string, dec uint, decPoint, thousandsSep st
}
// InterfaceToFloat64OrZeroValue returns the type assertion value or variable zero value
func InterfaceToFloat64OrZeroValue(r interface{}) float64 {
func InterfaceToFloat64OrZeroValue(r any) float64 {
if v, ok := r.(float64); ok {
return v
}
@@ -175,7 +175,7 @@ func InterfaceToFloat64OrZeroValue(r interface{}) float64 {
}
// InterfaceToIntOrZeroValue returns the type assertion value or variable zero value
func InterfaceToIntOrZeroValue(r interface{}) int {
func InterfaceToIntOrZeroValue(r any) int {
if v, ok := r.(int); ok {
return v
}
@@ -183,7 +183,7 @@ func InterfaceToIntOrZeroValue(r interface{}) int {
}
// InterfaceToStringOrZeroValue returns the type assertion value or variable zero value
func InterfaceToStringOrZeroValue(r interface{}) string {
func InterfaceToStringOrZeroValue(r any) string {
if v, ok := r.(string); ok {
return v
}

View File

@@ -196,7 +196,7 @@ func TestNumberToHumanFriendlyString(t *testing.T) {
}
func TestInterfaceToFloat64OrZeroValue(t *testing.T) {
var x interface{}
var x any
if r := InterfaceToFloat64OrZeroValue(x); r != 0 {
t.Errorf("expected 0, got: %v", r)
}
@@ -207,7 +207,7 @@ func TestInterfaceToFloat64OrZeroValue(t *testing.T) {
}
func TestInterfaceToIntOrZeroValue(t *testing.T) {
var x interface{}
var x any
if r := InterfaceToIntOrZeroValue(x); r != 0 {
t.Errorf("expected 0, got: %v", r)
}
@@ -218,7 +218,7 @@ func TestInterfaceToIntOrZeroValue(t *testing.T) {
}
func TestInterfaceToStringOrZeroValue(t *testing.T) {
var x interface{}
var x any
if r := InterfaceToStringOrZeroValue(x); r != "" {
t.Errorf("expected empty string, got: %v", r)
}