parseURL parses the given string as a URL and ensures that the path ends with a slash. If the input string is empty, it returns an error. If the URL cannot be parsed, it returns the parsing error.
(s string)
| 16 | // with a slash. If the input string is empty, it returns an error. If the URL |
| 17 | // cannot be parsed, it returns the parsing error. |
| 18 | func parseURL(s string) (*url.URL, error) { |
| 19 | if s == "" { |
| 20 | return nil, errors.New("url cannot be empty") |
| 21 | } |
| 22 | |
| 23 | u, err := url.Parse(s) |
| 24 | if err != nil { |
| 25 | return nil, fmt.Errorf("invalid url: %w", err) |
| 26 | } |
| 27 | |
| 28 | if !strings.HasSuffix(u.Path, "/") { |
| 29 | u.Path += "/" |
| 30 | } |
| 31 | |
| 32 | return u, nil |
| 33 | } |
no outgoing calls
searching dependent graphs…