Path defines an API or service base path, i.e. a common HTTP path prefix to all the API or service methods. The path may define wildcards (see GET for a description of the wildcard syntax). The corresponding parameters must be described using Params. Multiple base paths may be defined for services.
(val string)
| 237 | // |
| 238 | // Path accepts one argument: the HTTP path prefix. |
| 239 | func Path(val string) { |
| 240 | switch def := eval.Current().(type) { |
| 241 | case *expr.RootExpr: |
| 242 | if expr.Root.API.HTTP.Path != "" { |
| 243 | eval.ReportError(`only one base path may be specified for an API, got base paths %q and %q`, expr.Root.API.HTTP.Path, val) |
| 244 | } |
| 245 | expr.Root.API.HTTP.Path = val |
| 246 | case *expr.HTTPServiceExpr: |
| 247 | if !strings.HasPrefix(val, "//") { |
| 248 | rp := def.Root.Path |
| 249 | awcs := expr.ExtractHTTPWildcards(rp) |
| 250 | wcs := expr.ExtractHTTPWildcards(val) |
| 251 | for _, awc := range awcs { |
| 252 | for _, wc := range wcs { |
| 253 | if awc == wc { |
| 254 | eval.ReportError(`duplicate wildcard "%s" in API and service base paths`, wc) |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | def.Paths = append(def.Paths, val) |
| 260 | default: |
| 261 | eval.IncompatibleDSL() |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | // GET defines a route using the GET HTTP method. The route may use wildcards to |
| 266 | // define path parameters. Wildcards start with '{' or with '{*' and end with |
no test coverage detected