mirror of
https://github.com/hanzoai/migrate.git
synced 2026-09-30 22:55:10 +00:00
* Let database.Open() use schemeFromURL as well Otherwise it will fail on MySQL DSNs. Moved schemeFromURL into the database package. Also removed databaseSchemeFromURL and sourceSchemeFromURL as they were just calling schemeFromURL. Fixes https://github.com/golang-migrate/migrate/pull/265#issuecomment-522301237 * Moved url functions into internal/url Also merged the test cases. * Add some database tests to improve coverage * Fix suggestions
26 lines
423 B
Go
26 lines
423 B
Go
package url
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
var errNoScheme = errors.New("no scheme")
|
|
var errEmptyURL = errors.New("URL cannot be empty")
|
|
|
|
// schemeFromURL returns the scheme from a URL string
|
|
func SchemeFromURL(url string) (string, error) {
|
|
if url == "" {
|
|
return "", errEmptyURL
|
|
}
|
|
|
|
i := strings.Index(url, ":")
|
|
|
|
// No : or : is the first character.
|
|
if i < 1 {
|
|
return "", errNoScheme
|
|
}
|
|
|
|
return url[0:i], nil
|
|
}
|