| 113 | } |
| 114 | |
| 115 | func Parse(goGetterSrc string) (*Source, error) { |
| 116 | items := strings.Split(goGetterSrc, "::") |
| 117 | var getter string |
| 118 | if len(items) == 2 { |
| 119 | getter = items[0] |
| 120 | goGetterSrc = items[1] |
| 121 | } else { |
| 122 | items = strings.Split(goGetterSrc, "://") |
| 123 | |
| 124 | if len(items) == 2 { |
| 125 | return ParseNormal(goGetterSrc) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Local absolute paths (e.g., C:\path on Windows, /path on Unix) |
| 130 | // are not remote URLs. Reject them before go-getter's url.Parse |
| 131 | // can misinterpret Windows drive letters as URL schemes. |
| 132 | if filepath.IsAbs(goGetterSrc) { |
| 133 | return nil, InvalidURLError{err: fmt.Sprintf("parse url: local absolute path is not a remote URL: %s", goGetterSrc)} |
| 134 | } |
| 135 | |
| 136 | u, err := url.Parse(goGetterSrc) |
| 137 | if err != nil { |
| 138 | return nil, InvalidURLError{err: fmt.Sprintf("parse url: %v", err)} |
| 139 | } |
| 140 | |
| 141 | if u.Scheme == "" { |
| 142 | return nil, InvalidURLError{err: fmt.Sprintf("parse url: missing scheme - probably this is a local file path? %s", goGetterSrc)} |
| 143 | } |
| 144 | |
| 145 | pathComponents := strings.Split(u.Path, "@") |
| 146 | if len(pathComponents) != 2 { |
| 147 | dir := filepath.Dir(u.Path) |
| 148 | if len(dir) > 0 { |
| 149 | dir = dir[1:] |
| 150 | } |
| 151 | pathComponents = []string{dir, filepath.Base(u.Path)} |
| 152 | } |
| 153 | |
| 154 | return &Source{ |
| 155 | Getter: getter, |
| 156 | User: u.User.String(), |
| 157 | Scheme: u.Scheme, |
| 158 | Host: u.Host, |
| 159 | Dir: pathComponents[0], |
| 160 | File: pathComponents[1], |
| 161 | RawQuery: u.RawQuery, |
| 162 | }, nil |
| 163 | } |
| 164 | |
| 165 | func ParseNormal(path string) (*Source, error) { |
| 166 | _, err := ParseNormalProtocol(path) |