readFileResource reads from the filesystem at a URI relative to dirFilepath, respecting the roots. dirFilepath and rootFilepaths are absolute filesystem paths.
(rawURI, dirFilepath string, rootFilepaths []string)
| 51 | // the roots. |
| 52 | // dirFilepath and rootFilepaths are absolute filesystem paths. |
| 53 | func readFileResource(rawURI, dirFilepath string, rootFilepaths []string) ([]byte, error) { |
| 54 | uriFilepath, err := computeURIFilepath(rawURI, dirFilepath, rootFilepaths) |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | var data []byte |
| 60 | err = withFile(dirFilepath, uriFilepath, func(f *os.File) error { |
| 61 | var err error |
| 62 | data, err = io.ReadAll(f) |
| 63 | return err |
| 64 | }) |
| 65 | if os.IsNotExist(err) { |
| 66 | err = ResourceNotFoundError(rawURI) |
| 67 | } |
| 68 | return data, err |
| 69 | } |
| 70 | |
| 71 | // computeURIFilepath returns a path relative to dirFilepath. |
| 72 | // The dirFilepath and rootFilepaths are absolute file paths. |
searching dependent graphs…