URL returns the current working URL.
()
| 420 | |
| 421 | // URL returns the current working URL. |
| 422 | func (r *Request) URL() *url.URL { |
| 423 | p := r.pathPrefix |
| 424 | if r.namespaceSet && len(r.namespace) > 0 { |
| 425 | p = path.Join(p, "namespaces", r.namespace) |
| 426 | } |
| 427 | if len(r.resource) != 0 { |
| 428 | p = path.Join(p, strings.ToLower(r.resource)) |
| 429 | } |
| 430 | // Join trims trailing slashes, so preserve r.pathPrefix's trailing slash for backwards compatibility if nothing was changed |
| 431 | if len(r.resourceName) != 0 || len(r.subpath) != 0 || len(r.subresource) != 0 { |
| 432 | p = path.Join(p, r.resourceName, r.subresource, r.subpath) |
| 433 | } |
| 434 | |
| 435 | finalURL := &url.URL{} |
| 436 | if r.baseURL != nil { |
| 437 | *finalURL = *r.baseURL |
| 438 | } |
| 439 | finalURL.Path = p |
| 440 | |
| 441 | query := url.Values{} |
| 442 | for key, values := range r.params { |
| 443 | for _, value := range values { |
| 444 | query.Add(key, value) |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // timeout is handled specially here. |
| 449 | if r.timeout != 0 { |
| 450 | query.Set("timeout", r.timeout.String()) |
| 451 | } |
| 452 | finalURL.RawQuery = query.Encode() |
| 453 | return finalURL |
| 454 | } |
| 455 | |
| 456 | // finalURLTemplate is similar to URL(), but will make all specific parameter values equal |
| 457 | // - instead of name or namespace, "{name}" and "{namespace}" will be used, and all query |