🔀 Merge branch 'rel/0.0.8' into stable
This commit is contained in:
commit
d64102cea4
3 changed files with 32 additions and 0 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [0.0.8] - 2026-02-01
|
||||||
|
|
||||||
|
- ✨ Add Get method to Metas type
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [0.0.7] - 2025-11-05
|
## [0.0.7] - 2025-11-05
|
||||||
|
|
||||||
- 🚚 Refactor project structure to follow standard Go layout (cmd/my-log/ and internal/cmd/)
|
- 🚚 Refactor project structure to follow standard Go layout (cmd/my-log/ and internal/cmd/)
|
||||||
|
|
|
||||||
|
|
@ -141,3 +141,19 @@ func TestMetasAppendTo(t *testing.T) {
|
||||||
assert.Len(t, *ms, 1)
|
assert.Len(t, *ms, 1)
|
||||||
assert.Equal(t, Meta{"foo", 42}, (*ms)[0])
|
assert.Equal(t, Meta{"foo", 42}, (*ms)[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMetasGet(t *testing.T) {
|
||||||
|
ms := Metas{{"foo", 42}, {"bar", "hello"}}
|
||||||
|
|
||||||
|
val, found := ms.Get("foo")
|
||||||
|
assert.True(t, found)
|
||||||
|
assert.Equal(t, 42, val)
|
||||||
|
|
||||||
|
val, found = ms.Get("bar")
|
||||||
|
assert.True(t, found)
|
||||||
|
assert.Equal(t, "hello", val)
|
||||||
|
|
||||||
|
val, found = ms.Get("baz")
|
||||||
|
assert.False(t, found)
|
||||||
|
assert.Nil(t, val)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,3 +69,13 @@ func (ms *Metas) AppendTo(k string, v any) {
|
||||||
n := (*ms).Append(k, v)
|
n := (*ms).Append(k, v)
|
||||||
*ms = n
|
*ms = n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the value of the Meta with the given key, and a bool indicating if it was found
|
||||||
|
func (ms Metas) Get(key string) (any, bool) {
|
||||||
|
for _, m := range ms {
|
||||||
|
if m.Key == key {
|
||||||
|
return m.Value, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue