makeURL returns a URL based on initialURL that contains the config contents as parameters. The second result is true iff a parameter value was changed.
(initialURL url.URL)
| 342 | // makeURL returns a URL based on initialURL that contains the config contents |
| 343 | // as parameters. The second result is true iff a parameter value was changed. |
| 344 | func (cfg *config) makeURL(initialURL url.URL) (url.URL, bool) { |
| 345 | q := initialURL.Query() |
| 346 | changed := false |
| 347 | for _, f := range configFields { |
| 348 | if f.urlparam == "" || !f.saved { |
| 349 | continue |
| 350 | } |
| 351 | v := cfg.get(f) |
| 352 | if v == f.defaultValue { |
| 353 | v = "" // URL for of default value is the empty string. |
| 354 | } else if f.field.Type.Kind() == reflect.Bool { |
| 355 | // Shorten bool values to "f" or "t" |
| 356 | v = v[:1] |
| 357 | } |
| 358 | if q.Get(f.urlparam) == v { |
| 359 | continue |
| 360 | } |
| 361 | changed = true |
| 362 | if v == "" { |
| 363 | q.Del(f.urlparam) |
| 364 | } else { |
| 365 | q.Set(f.urlparam, v) |
| 366 | } |
| 367 | } |
| 368 | if changed { |
| 369 | initialURL.RawQuery = q.Encode() |
| 370 | } |
| 371 | return initialURL, changed |
| 372 | } |