End isFilePath
(inputURL string)
| 82 | return true, nil // File exists |
| 83 | } // End isFilePath |
| 84 | func loadFromURL(inputURL string) (string, error) { // Load schema from URL |
| 85 | // Parse and validate the URL |
| 86 | parsedURL, err := url.Parse(inputURL) |
| 87 | if err != nil { |
| 88 | return "", err |
| 89 | } |
| 90 | // Add checks here to validate the scheme, host, etc., of parsedURL |
| 91 | // For example, ensure the scheme is either http or https |
| 92 | if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" { |
| 93 | return "", errors.New("invalid URL scheme") |
| 94 | } |
| 95 | // Perform the HTTP GET request |
| 96 | resp, err := http.Get(parsedURL.String()) |
| 97 | if err != nil { // HTTP request failed |
| 98 | return "", err // Return error |
| 99 | } // Request succeeded |
| 100 | defer resp.Body.Close() // Ensure cleanup |
| 101 | // Read the response body |
| 102 | body, err := io.ReadAll(resp.Body) // Read response |
| 103 | if err != nil { // Read failed |
| 104 | return "", err // Return error |
| 105 | } // Read succeeded |
| 106 | return string(body), nil // Return body |
| 107 | } // End loadFromURL |
| 108 | func loadFromFile(path string) (string, error) { // Load schema from file |
| 109 | // Clean the path |
| 110 | cleanPath := filepath.Clean(path) |
no test coverage detected