zntg/ui/fallbackresources.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
897 B
Go

package ui
import "io"
var _ Resources = &fallbackResources{}
type fallbackResources struct {
resources Resources
fallback Resources
}
// NewFallbackResources creates a Resources that first will try to access resources and on failure will try to access the fallback resources. Will take ownership of both resources (Destroy).
func NewFallbackResources(resources, fallback Resources) Resources {
return &fallbackResources{resources, fallback}
}
func (r *fallbackResources) OpenResource(name string) (io.ReadCloser, error) {
if reader, err := r.resources.OpenResource(name); err == nil {
return reader, nil
}
return r.fallback.OpenResource(name)
}
func (r *fallbackResources) Destroy() error {
errResources := r.resources.Destroy()
errFallback := r.fallback.Destroy()
if errResources != nil {
return errResources
}
if errFallback != nil {
return errFallback
}
return nil
}