Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: Yijie Qin <qinyijie@amazon.com>
  • Loading branch information
qinxx108 committed Jul 5, 2023
1 parent b1ee40a commit 35fa146
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions dispatch/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 35fa146

Please sign in to comment.