MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / Parse

Function Parse

internal/httprule/parse.go:20–37  ·  view source on GitHub ↗

Parse parses the string representation of path template

(tmpl string)

Source from the content-addressed store, hash-verified

18
19// Parse parses the string representation of path template
20func 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
39func tokenize(path string) (tokens []string, verb string) {
40 if path == "" {

Callers 8

compilePathFunction · 0.92
compilePathFunction · 0.92
newMethodMethod · 0.92
HandlePathMethod · 0.92
TestParseFunction · 0.85
TestParseErrorFunction · 0.85
FuzzFunction · 0.85

Calls 3

topLevelSegmentsMethod · 0.95
tokenizeFunction · 0.85
ErrorMethod · 0.45

Tested by 5

compilePathFunction · 0.74
compilePathFunction · 0.74
TestParseFunction · 0.68
TestParseErrorFunction · 0.68