zntg/ui/osresources.go
Sander Schobers 67e73a8671 Resources only exposes OpenResource (and Destroy).
PhysicalResources derives from Resources and exposes FetchResource.
Made dependency specific resource addons.
Extended the available resource options (fallback, path, refactored copy).
NewRenderer provides DefaultResources to the created renderer.
2020-05-25 22:24:06 +02:00

35 lines
797 B
Go

package ui
import (
"io"
"os"
)
var _ PhysicalResources = &OSResources{}
// DefaultResources returns the default Resources implementation (OSResources).
func DefaultResources() PhysicalResources {
return &OSResources{}
}
// OSResources is Resources implementation that uses the default file system directly.
type OSResources struct {
}
// FetchResource checks if file is available and returns the specified path.
func (r *OSResources) FetchResource(name string) (string, error) {
_, err := os.Stat(name)
if err != nil {
return "", err
}
return name, nil
}
// OpenResource opens the specified file on disk.
func (r *OSResources) OpenResource(name string) (io.ReadCloser, error) {
return os.Open(name)
}
// Destroy does nothing.
func (r *OSResources) Destroy() error { return nil }