diff --git a/migrate.go b/migrate.go index db53aaf..8a6c7f0 100644 --- a/migrate.go +++ b/migrate.go @@ -66,13 +66,13 @@ type Migrate struct { func New(sourceUrl, databaseUrl string) (*Migrate, error) { m := newCommon() - sourceName, err := nameFromUrl(sourceUrl) + sourceName, err := schemeFromUrl(sourceUrl) if err != nil { return nil, err } m.sourceName = sourceName - databaseName, err := nameFromUrl(databaseUrl) + databaseName, err := schemeFromUrl(databaseUrl) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func New(sourceUrl, databaseUrl string) (*Migrate, error) { func NewWithDatabaseInstance(sourceUrl string, databaseName string, databaseInstance database.Driver) (*Migrate, error) { m := newCommon() - sourceName, err := nameFromUrl(sourceUrl) + sourceName, err := schemeFromUrl(sourceUrl) if err != nil { return nil, err } @@ -126,7 +126,7 @@ func NewWithDatabaseInstance(sourceUrl string, databaseName string, databaseInst func NewWithSourceInstance(sourceName string, sourceInstance source.Driver, databaseUrl string) (*Migrate, error) { m := newCommon() - databaseName, err := nameFromUrl(databaseUrl) + databaseName, err := schemeFromUrl(databaseUrl) if err != nil { return nil, err } diff --git a/util.go b/util.go index a92e359..ea5ea8f 100644 --- a/util.go +++ b/util.go @@ -46,8 +46,8 @@ func suint(n int) uint { return uint(n) } -// newSlowReader turns an io.Reader into a slow io.Reader -// use to simulate a slow internet connection +// newSlowReader turns an io.ReadCloser into a slow io.ReadCloser. +// Use this to simulate a slow internet connection. func newSlowReader(r io.ReadCloser) io.ReadCloser { return &slowReader{ rx: r, @@ -75,16 +75,17 @@ func (b *slowReader) Close() error { return b.rx.Close() } -var errNoName = fmt.Errorf("no name") +var errNoScheme = fmt.Errorf("no scheme") -func nameFromUrl(url string) (string, error) { +// schemeFromUrl returns the scheme from a URL string +func schemeFromUrl(url string) (string, error) { u, err := nurl.Parse(url) if err != nil { return "", err } if len(u.Scheme) == 0 { - return "", errNoName + return "", errNoScheme } return u.Scheme, nil