mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-30 05:41:50 +02:00
style: coed cleanup and fix styling
This commit is contained in:
@@ -26,11 +26,11 @@ func AppendDuration(d time.Duration, buf []byte) []byte {
|
||||
|
||||
switch {
|
||||
case d < time.Millisecond:
|
||||
buf = strconv.AppendInt(buf, int64(d.Nanoseconds()), 10)
|
||||
buf = strconv.AppendInt(buf, d.Nanoseconds(), 10)
|
||||
buf = append(buf, []byte(" ns")...)
|
||||
return buf
|
||||
case d < time.Second:
|
||||
buf = strconv.AppendInt(buf, int64(d.Milliseconds()), 10)
|
||||
buf = strconv.AppendInt(buf, d.Milliseconds(), 10)
|
||||
buf = append(buf, []byte(" ms")...)
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestFormatTime(t *testing.T) {
|
||||
result := FormatTimeWithReference(tt.time, now)
|
||||
|
||||
if tt.expectedLength > 0 {
|
||||
require.Equal(t, tt.expectedLength, len(result), result)
|
||||
require.Len(t, result, tt.expectedLength)
|
||||
} else {
|
||||
require.Equal(t, tt.expected, result)
|
||||
}
|
||||
@@ -213,11 +213,8 @@ func TestFormatLastSeen(t *testing.T) {
|
||||
|
||||
if tt.name == "zero time" {
|
||||
require.Equal(t, tt.expected, result)
|
||||
} else {
|
||||
// Just make sure it's not "never", the actual formatting is tested in TestFormatTime
|
||||
if result == "never" {
|
||||
t.Errorf("Expected non-zero time to not return 'never', got %s", result)
|
||||
}
|
||||
} else if result == "never" { // Just make sure it's not "never", the actual formatting is tested in TestFormatTime
|
||||
t.Errorf("Expected non-zero time to not return 'never', got %s", result)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ func (p *Pool[T]) Get() []T {
|
||||
|
||||
func (p *Pool[T]) Put(b []T) {
|
||||
if cap(b) <= p.maxSize {
|
||||
p.pool.Put(b[:0])
|
||||
p.pool.Put(b[:0]) //nolint:staticcheck
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ import (
|
||||
"slices"
|
||||
)
|
||||
|
||||
type YieldFunc = func(part string, value any) bool
|
||||
type YieldKeyFunc = func(key string) bool
|
||||
type Iterator = func(YieldFunc)
|
||||
type KeyIterator = func(YieldKeyFunc)
|
||||
type (
|
||||
YieldFunc = func(part string, value any) bool
|
||||
YieldKeyFunc = func(key string) bool
|
||||
Iterator = func(YieldFunc)
|
||||
KeyIterator = func(YieldKeyFunc)
|
||||
)
|
||||
|
||||
// WalkAll walks all nodes in the trie, yields full key and series
|
||||
func (node *Node) Walk(yield YieldFunc) {
|
||||
@@ -17,10 +19,7 @@ func (node *Node) Walk(yield YieldFunc) {
|
||||
|
||||
func (node *Node) walkAll(yield YieldFunc) bool {
|
||||
if !node.value.IsNil() {
|
||||
if !yield(node.key, node.value.Load()) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
return yield(node.key, node.value.Load())
|
||||
}
|
||||
for _, v := range node.children.Range {
|
||||
if !v.walkAll(yield) {
|
||||
@@ -57,10 +56,9 @@ func (node *Node) Map() map[string]any {
|
||||
func (tree Root) Query(key *Key) Iterator {
|
||||
if !key.hasWildcard {
|
||||
return func(yield YieldFunc) {
|
||||
if v, ok := tree.Node.Get(key); ok {
|
||||
if v, ok := tree.Get(key); ok {
|
||||
yield(key.full, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
return func(yield YieldFunc) {
|
||||
|
||||
Reference in New Issue
Block a user