rename nameFromUrl to schemeFromUrl

This commit is contained in:
Matthias Kadenbach 2017-02-09 18:19:13 -08:00
parent 46c16bb8f1
commit 8ba71b0754
2 changed files with 10 additions and 9 deletions

View File

@ -66,13 +66,13 @@ type Migrate struct {
func New(sourceUrl, databaseUrl string) (*Migrate, error) { func New(sourceUrl, databaseUrl string) (*Migrate, error) {
m := newCommon() m := newCommon()
sourceName, err := nameFromUrl(sourceUrl) sourceName, err := schemeFromUrl(sourceUrl)
if err != nil { if err != nil {
return nil, err return nil, err
} }
m.sourceName = sourceName m.sourceName = sourceName
databaseName, err := nameFromUrl(databaseUrl) databaseName, err := schemeFromUrl(databaseUrl)
if err != nil { if err != nil {
return nil, err 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) { func NewWithDatabaseInstance(sourceUrl string, databaseName string, databaseInstance database.Driver) (*Migrate, error) {
m := newCommon() m := newCommon()
sourceName, err := nameFromUrl(sourceUrl) sourceName, err := schemeFromUrl(sourceUrl)
if err != nil { if err != nil {
return nil, err 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) { func NewWithSourceInstance(sourceName string, sourceInstance source.Driver, databaseUrl string) (*Migrate, error) {
m := newCommon() m := newCommon()
databaseName, err := nameFromUrl(databaseUrl) databaseName, err := schemeFromUrl(databaseUrl)
if err != nil { if err != nil {
return nil, err return nil, err
} }

11
util.go
View File

@ -46,8 +46,8 @@ func suint(n int) uint {
return uint(n) return uint(n)
} }
// newSlowReader turns an io.Reader into a slow io.Reader // newSlowReader turns an io.ReadCloser into a slow io.ReadCloser.
// use to simulate a slow internet connection // Use this to simulate a slow internet connection.
func newSlowReader(r io.ReadCloser) io.ReadCloser { func newSlowReader(r io.ReadCloser) io.ReadCloser {
return &slowReader{ return &slowReader{
rx: r, rx: r,
@ -75,16 +75,17 @@ func (b *slowReader) Close() error {
return b.rx.Close() 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) u, err := nurl.Parse(url)
if err != nil { if err != nil {
return "", err return "", err
} }
if len(u.Scheme) == 0 { if len(u.Scheme) == 0 {
return "", errNoName return "", errNoScheme
} }
return u.Scheme, nil return u.Scheme, nil