load loads the given resource into memory.
(url string)
| 85 | |
| 86 | // load loads the given resource into memory. |
| 87 | func (formats *Formats) load(url string) error { |
| 88 | ext := getExt(url) |
| 89 | if loader, ok := Files.formats[ext]; ok { |
| 90 | f, err := openFile(filepath.Join(formats.root, url)) |
| 91 | if err != nil { |
| 92 | return fmt.Errorf("unable to open resource: %s", err) |
| 93 | } |
| 94 | defer f.Close() |
| 95 | |
| 96 | // This specific loader needs to be given the root |
| 97 | rl, ok := loader.(FileLoaderRooter) |
| 98 | if ok { |
| 99 | rl.SetRoot(formats.GetRoot()) |
| 100 | } |
| 101 | |
| 102 | return loader.Load(url, f) |
| 103 | } |
| 104 | return fmt.Errorf("no `FileLoader` associated with this extension: %q in url %q", ext, url) |
| 105 | } |
| 106 | |
| 107 | // Load loads the given resource(s) into memory, stopping at the first error. |
| 108 | func (formats *Formats) Load(urls ...string) error { |