func (tr *traverser) Done() bool {
	return tr.done
}
Done returns true iff this traversal has been marked finished.
package gomodel
import (
	"fmt"
	"strings"
)
func FindValuesMatching(first, second PathTemplate) (fullMatch bool, longestMatch string, err error) {
	one := &traverser{template: first.Flatten()}
	two := &traverser{template: second.Flatten()}
	values := make([]string, max(one.Len(), two.Len()))
	defer func() {
		longestMatch = strings.Join(values, "")
	}()
	for !(one.Done() || two.Done()) {
		matches, matching := segmentsMatch(one, two)
		if !matches {
			return false, "", nil
		}
		values = append(values, matching)
	}
	one.ConsumeIfKind(MultipleValue)
	two.ConsumeIfKind(MultipleValue)
	if one.ConsumedAll() && two.ConsumedAll() {
		return true, "", nil
	}
	if !(one.ConsumedAll() || two.ConsumedAll()) {
		return false, "", fmt.Errorf("did not traverse either full pattern one: %v    two: %v", *one, *two)
	}
	return false, "", nil
}
func segmentsMatch(one, two *traverser) (bool, string) {
	seg1 := one.Segment()
	seg2 := two.Segment()
	if seg1.Kind != Literal && seg2.Kind == Literal {
		return segmentsMatch(two, one)
	}
	if seg1.Kind == Literal {
		switch seg2.Kind {
		case Literal:
			if seg1.Value != seg2.Value {
				return false, ""
			}
			one.Inc()
			two.Inc()
			return true, seg1.Value
		case SingleValue:
			one.Inc()
			two.Inc()
			return true, seg1.Value
		case MultipleValue:
			if seg1.Value == ":" {
				two.Inc()
				return true, ""
			}
			one.Inc()
			return true, seg1.Value
		default:
			one.SetDone()
			two.SetDone()
			return false, "[ERROR]"
		}
	}
	if seg1.Kind != SingleValue && seg2.Kind == SingleValue {
		return segmentsMatch(two, one)
	}
	if seg1.Kind == SingleValue {
		switch seg2.Kind {
		case SingleValue:
			one.Inc()
			two.Inc()
			return true, "*"
		case MultipleValue:
			one.Inc()
			return true, "*"
		default:
			one.SetDone()
			two.SetDone()
			return false, "[ERROR]"
		}
	}
	if seg1.Kind == MultipleValue {
		if seg2.Kind != MultipleValue {
			one.SetDone()
			two.SetDone()
			return false, fmt.Sprintf("[ERROR: unknown SegmentKind %d]", seg2.Kind)
		}
		one.Inc()
		two.Inc()
		return true, "**"
	}
	one.SetDone()
	two.SetDone()
	return false, fmt.Sprintf("[ERROR: unknown SegmentKind %d]", seg1.Kind)
}
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
type traverser struct {
	template PathTemplate
	idx int
	done bool
}
func (tr *traverser) Segment() *Segment {
	return tr.template[tr.idx]
}
func (tr *traverser) Len() int {
	return len(tr.template)
}
func (tr *traverser) Inc() {
	tr.idx++
	if tr.ConsumedAll() {
		tr.SetDone()
	}
}
func (tr *traverser) ConsumeIfKind(kind SegmentKind) {
	if !tr.Done() && tr.template[tr.idx].Kind == kind {
		tr.Inc()
	}
}
func (tr *traverser) ConsumedAll() bool {
	return tr.idx >= len(tr.template)
}