github.com/bishtawi/migrate/v4@v4.8.11/internal/url/url.go (about) 1 package url 2 3 import ( 4 "errors" 5 "strings" 6 ) 7 8 var errNoScheme = errors.New("no scheme") 9 var errEmptyURL = errors.New("URL cannot be empty") 10 11 // schemeFromURL returns the scheme from a URL string 12 func SchemeFromURL(url string) (string, error) { 13 if url == "" { 14 return "", errEmptyURL 15 } 16 17 i := strings.Index(url, ":") 18 19 // No : or : is the first character. 20 if i < 1 { 21 return "", errNoScheme 22 } 23 24 return url[0:i], nil 25 }