From cccac79439448990cc712d2b266d776aa926dde9 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 1 Feb 2026 11:29:04 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20Get=20method=20to=20Metas=20t?= =?UTF-8?q?ype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/meta_test.go | 16 ++++++++++++++++ models/metas.go | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/models/meta_test.go b/models/meta_test.go index 2d4cea8..6fa6141 100644 --- a/models/meta_test.go +++ b/models/meta_test.go @@ -141,3 +141,19 @@ func TestMetasAppendTo(t *testing.T) { assert.Len(t, *ms, 1) 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) +} diff --git a/models/metas.go b/models/metas.go index 4db9d46..9ed7006 100644 --- a/models/metas.go +++ b/models/metas.go @@ -69,3 +69,13 @@ func (ms *Metas) AppendTo(k string, v any) { n := (*ms).Append(k, v) *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 +}