Parse parses the string representation of path template
(tmpl string)
| 18 | |
| 19 | // Parse parses the string representation of path template |
| 20 | func Parse(tmpl string) (Compiler, error) { |
| 21 | if !strings.HasPrefix(tmpl, "/") { |
| 22 | return template{}, InvalidTemplateError{tmpl: tmpl, msg: "no leading /"} |
| 23 | } |
| 24 | tokens, verb := tokenize(tmpl[1:]) |
| 25 | |
| 26 | p := parser{tokens: tokens} |
| 27 | segs, err := p.topLevelSegments() |
| 28 | if err != nil { |
| 29 | return template{}, InvalidTemplateError{tmpl: tmpl, msg: err.Error()} |
| 30 | } |
| 31 | |
| 32 | return template{ |
| 33 | segments: segs, |
| 34 | verb: verb, |
| 35 | template: tmpl, |
| 36 | }, nil |
| 37 | } |
| 38 | |
| 39 | func tokenize(path string) (tokens []string, verb string) { |
| 40 | if path == "" { |