(path string, w string, funcArgPos int)
| 217 | } |
| 218 | |
| 219 | func (p *methodParser) parsePathParam(path string, w string, funcArgPos int) (string, int, error) { |
| 220 | typ := p.fn.Type |
| 221 | |
| 222 | if typ.NumIn() <= funcArgPos { |
| 223 | |
| 224 | // By found but input arguments are not there, so act like /by path without restricts. |
| 225 | path = addPathWord(path, w) |
| 226 | return path, funcArgPos, nil |
| 227 | } |
| 228 | |
| 229 | var ( |
| 230 | paramKey = genParamKey(funcArgPos) // argfirst, argsecond... |
| 231 | m = p.macros.GetMaster() // default (String by-default) |
| 232 | trailings = p.macros.GetTrailings() |
| 233 | ) |
| 234 | |
| 235 | // string, int... |
| 236 | goType := typ.In(funcArgPos).Kind() |
| 237 | nextWord := p.lexer.peekNext() |
| 238 | |
| 239 | if nextWord == tokenWildcard { |
| 240 | p.lexer.skip() // skip the Wildcard word. |
| 241 | if len(trailings) == 0 { |
| 242 | return "", 0, errors.New("no trailing path parameter found") |
| 243 | } |
| 244 | m = trailings[0] |
| 245 | } else { |
| 246 | // validMacros := p.macros.LookupForGoType(goType) |
| 247 | |
| 248 | // instead of mapping with a reflect.Kind which has its limitation, |
| 249 | // we map the param types with a go type as a string, |
| 250 | // so custom structs such as "user" can be mapped to a macro with indent || alias == "user". |
| 251 | m = p.macros.Get(strings.ToLower(goType.String())) |
| 252 | |
| 253 | if m == nil { |
| 254 | if typ.NumIn() > funcArgPos { |
| 255 | // has more input arguments but we are not in the correct |
| 256 | // index now, maybe the first argument was an `iris/context.Context` |
| 257 | // so retry with the "funcArgPos" incremented. |
| 258 | // |
| 259 | // the "funcArgPos" will be updated to the caller as well |
| 260 | // because we return it among the path and the error. |
| 261 | return p.parsePathParam(path, w, funcArgPos+1) |
| 262 | } |
| 263 | |
| 264 | return "", 0, fmt.Errorf("invalid syntax: the standard go type: %s found in controller's function: %s at position: %d does not match any valid macro", goType, p.fn.Name, funcArgPos) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // /{argfirst:path}, /{argfirst:int64}... |
| 269 | if path[len(path)-1] != '/' { |
| 270 | path += "/" |
| 271 | } |
| 272 | path += fmt.Sprintf("{%s:%s}", paramKey, m.Indent()) |
| 273 | |
| 274 | if nextWord == "" && typ.NumIn() > funcArgPos+1 { |
| 275 | // By is the latest word but func is expected |
| 276 | // more path parameters values, i.e: |
no test coverage detected