From 35fa14641e24c93e1eeeca63f3f7f807ea824a9d Mon Sep 17 00:00:00 2001 From: Yijie Qin Date: Wed, 5 Jul 2023 00:16:07 -0400 Subject: [PATCH] address comment Signed-off-by: Yijie Qin --- dispatch/route.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dispatch/route.go b/dispatch/route.go index 8ccf3a625a..39359af920 100644 --- a/dispatch/route.go +++ b/dispatch/route.go @@ -180,25 +180,26 @@ func (r *Route) Key() string { return b.String() } -// ID returns a unique identifier for the route, unlike Key(). +// ID returns a unique identifier for the route, unlike Key(). This need to be called after full route tree +// finish generated as it need to know the position of this route in the whole tree func (r *Route) ID() string { b := strings.Builder{} - var position *int + position := -1 if r.parent != nil { // Find the position in the same level leaf. for i, cr := range r.parent.Routes { if cr == r { - position = &i + position = i break } } } b.WriteString(r.Key()) - if position != nil { + if position > -1 { b.WriteRune('/') - b.WriteString(fmt.Sprint(*position)) + b.WriteString(fmt.Sprint(position)) } return b.String() }