End loadFromURL
(path string)
| 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) |
| 111 | // Check if the cleaned path is trying to traverse directories |
| 112 | if filepath.IsAbs(cleanPath) || strings.HasPrefix(cleanPath, "..") { |
| 113 | return "", errors.New("invalid file path") |
| 114 | } |
| 115 | content, err := os.ReadFile(path) // Read file |
| 116 | if err != nil { // Read failed |
| 117 | return "", err // Return error |
| 118 | } // Read succeeded |
| 119 | return string(content), nil // Return content |
| 120 | } // End loadFromFile |
| 121 | // loadInline is a function that handles inline schema types. |
| 122 | func loadInline(schema string) (string, error) { // Load inline schema |
| 123 | // Add validation if necessary. For example: |