MCPcopy Index your code
hub / github.com/kataras/iris / parse

Method parse

mvc/controller_method_parser.go:161–217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

159}
160
161func (p *methodParser) parse() (method, path string, err error) {
162 funcArgPos := 0
163 path = "/"
164 // take the first word and check for the method.
165 w := p.lexer.next()
166
167 for _, httpMethod := range allMethods {
168 possibleMethodFuncName := methodTitle(httpMethod)
169 if strings.Index(w, possibleMethodFuncName) == 0 {
170 method = httpMethod
171 break
172 }
173 }
174
175 if method == "" {
176 // this is not a valid method to parse, we just skip it,
177 // it may be used for end-dev's use cases.
178 return "", "", errSkip
179 }
180
181 wordIndex := 0
182 for {
183 w := p.lexer.next()
184 if w == "" {
185 break
186 }
187
188 if w == tokenBy {
189 funcArgPos++ // starting with 1 because in typ.NumIn() the first is the struct receiver.
190
191 // No need for these:
192 // ByBy will act like /{param:type}/{param:type} as users expected
193 // if func input arguments are there, else act By like normal path /by.
194 //
195 // if p.lexer.peekPrev() == tokenBy || typ.NumIn() == 1 { // ByBy, then act this second By like a path
196 // a.relPath += "/" + strings.ToLower(w)
197 // continue
198 // }
199
200 if path, funcArgPos, err = p.parsePathParam(path, w, funcArgPos); err != nil {
201 return "", "", err
202 }
203
204 continue
205 }
206
207 // custom static path.
208 if p.customPathWordFunc != nil {
209 path = p.customPathWordFunc(path, w, wordIndex)
210 } else {
211 // default static path.
212 path = addPathWord(path, w)
213 }
214 wordIndex++
215 }
216 return
217}
218

Callers 3

parseMethodFunction · 0.95
dropzone.jsFile · 0.80
bundle.jsFile · 0.80

Calls 5

parsePathParamMethod · 0.95
methodTitleFunction · 0.85
addPathWordFunction · 0.85
nextMethod · 0.80
IndexMethod · 0.65

Tested by

no test coverage detected