|
9 | 9 | ) |
10 | 10 |
|
11 | 11 | // OdbcIgnoreQueryPrefixes are the query prefixes to ignore when generating the |
12 | | -// odbc DSN. Used by GenOdbc |
| 12 | +// odbc DSN. Used by [GenOdbc]. |
13 | 13 | var OdbcIgnoreQueryPrefixes []string |
14 | 14 |
|
15 | 15 | // GenScheme returns a generator that will generate a scheme based on the |
@@ -427,7 +427,7 @@ func GenOdbc(u *URL) (string, string, error) { |
427 | 427 | } |
428 | 428 | // build q |
429 | 429 | q := u.Query() |
430 | | - q.Set("Driver", "{"+strings.Replace(u.Transport, "+", " ", -1)+"}") |
| 430 | + q.Set("Driver", "{"+strings.ReplaceAll(u.Transport, "+", " ")+"}") |
431 | 431 | q.Set("Server", host) |
432 | 432 | if port == "" { |
433 | 433 | proto := strings.ToLower(u.Transport) |
@@ -458,7 +458,7 @@ func GenOdbc(u *URL) (string, string, error) { |
458 | 458 | func GenOleodbc(u *URL) (string, string, error) { |
459 | 459 | props, _, err := GenOdbc(u) |
460 | 460 | if err != nil { |
461 | | - return "", "", nil |
| 461 | + return "", "", err |
462 | 462 | } |
463 | 463 | return `Provider=MSDASQL.1;Extended Properties="` + props + `"`, "", nil |
464 | 464 | } |
@@ -518,9 +518,10 @@ func GenPresto(u *URL) (string, string, error) { |
518 | 518 | } |
519 | 519 | // force port |
520 | 520 | if z.Port() == "" { |
521 | | - if z.Scheme == "http" { |
| 521 | + switch z.Scheme { |
| 522 | + case "http": |
522 | 523 | z.Host += ":8080" |
523 | | - } else if z.Scheme == "https" { |
| 524 | + case "https": |
524 | 525 | z.Host += ":8443" |
525 | 526 | } |
526 | 527 | } |
@@ -562,16 +563,12 @@ func GenSnowflake(u *URL) (string, string, error) { |
562 | 563 |
|
563 | 564 | // GenSpanner generates a spanner DSN from the passed URL. |
564 | 565 | func GenSpanner(u *URL) (string, string, error) { |
565 | | - project, instance, dbname := u.Hostname(), "", strings.TrimPrefix(u.Path, "/") |
| 566 | + project := u.Hostname() |
566 | 567 | if project == "" { |
567 | 568 | return "", "", ErrMissingHost |
568 | 569 | } |
569 | | - i := strings.Index(dbname, "/") |
570 | | - if i == -1 { |
571 | | - return "", "", ErrMissingPath |
572 | | - } |
573 | | - instance, dbname = dbname[:i], dbname[i+1:] |
574 | | - if instance == "" || dbname == "" { |
| 570 | + instance, dbname, ok := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/") |
| 571 | + if !ok || instance == "" || dbname == "" { |
575 | 572 | return "", "", ErrMissingPath |
576 | 573 | } |
577 | 574 | return fmt.Sprintf(`projects/%s/instances/%s/databases/%s`, project, instance, dbname), "", nil |
@@ -608,13 +605,14 @@ func GenSqlserver(u *URL) (string, string, error) { |
608 | 605 | func GenTableStore(u *URL) (string, string, error) { |
609 | 606 | var transport string |
610 | 607 | splits := strings.Split(u.OriginalScheme, "+") |
611 | | - if len(splits) == 0 { |
| 608 | + switch { |
| 609 | + case len(splits) == 0: |
612 | 610 | return "", "", ErrInvalidDatabaseScheme |
613 | | - } else if len(splits) == 1 || splits[1] == "https" { |
| 611 | + case len(splits) == 1, splits[1] == "https": |
614 | 612 | transport = "https" |
615 | | - } else if splits[1] == "http" { |
| 613 | + case splits[1] == "http": |
616 | 614 | transport = "http" |
617 | | - } else { |
| 615 | + default: |
618 | 616 | return "", "", ErrInvalidTransportProtocol |
619 | 617 | } |
620 | 618 | z := &url.URL{ |
@@ -708,6 +706,8 @@ func genOptionsOdbc(q url.Values, skipWhenEmpty bool, ignore, ignorePrefixes []s |
708 | 706 | // following: |
709 | 707 | // |
710 | 708 | // genOptions(u.Query(), "", "=", ";", ",", false) |
| 709 | +// |
| 710 | +//nolint:unparam |
711 | 711 | func genOptions(q url.Values, joiner, assign, sep, valSep string, skipWhenEmpty bool, ignore, ignorePrefixes []string) string { |
712 | 712 | if len(q) == 0 { |
713 | 713 | return "" |
|
0 commit comments