go-sample-webpage/vendor/github.com/golang-migrate/migrate/v4/internal/url/url.go

26 lines
423 B
Go
Raw Permalink Normal View History

2021-11-08 01:25:36 +00:00
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
}