From 17b54f8a8f6fb2aee3d5c36996eccdb3bd3e3e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 3 Aug 2022 20:59:17 +0200 Subject: [PATCH] prefix handler is leaf. --- internal/proxy/prefix.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/internal/proxy/prefix.go b/internal/proxy/prefix.go index 2da8e36..5d895ee 100644 --- a/internal/proxy/prefix.go +++ b/internal/proxy/prefix.go @@ -6,6 +6,7 @@ import ( type prefixHandler[T any] struct { Value T + IsLeaf bool Children map[string]*prefixHandler[T] } @@ -33,6 +34,7 @@ func (p *prefixHandler[T]) Set(prefix string, value T) { if i == len-1 { dat.Value = value + dat.IsLeaf = true dat.Children = nil } @@ -61,7 +63,7 @@ func (p *prefixHandler[T]) Get(prefix string) (value T, ok bool) { if i == len-1 { value = dat.Value - ok = dat.Children == nil + ok = dat.IsLeaf return } @@ -112,19 +114,13 @@ func (p *prefixHandler[T]) Match(path string) (value T, prefix string, ok bool) p = pointer prefixArr = append(prefixArr, a) - // if leaf node - if p.Children == nil { + if p.IsLeaf { break } } - // if not leaf node - if p.Children != nil { - return - } - value = p.Value prefix = "/" + strings.Join(prefixArr, "/") - ok = true + ok = p.IsLeaf return }