pkger/pkging/memware/open.go

33 lines
535 B
Go
Raw Normal View History

2019-09-02 00:58:20 +03:00
package memware
2019-09-01 00:00:24 +03:00
import (
"fmt"
2019-09-02 01:02:45 +03:00
"github.com/markbates/pkger/pkging"
2019-09-01 00:00:24 +03:00
)
2019-09-02 01:02:45 +03:00
func (fx *Warehouse) Open(name string) (pkging.File, error) {
2019-09-01 00:00:24 +03:00
pt, err := fx.Parse(name)
if err != nil {
return nil, err
}
fl, ok := fx.files.Load(pt)
if !ok {
return nil, fmt.Errorf("could not open %s", name)
}
f, ok := fl.(*File)
if !ok {
return nil, fmt.Errorf("could not open %s", name)
}
nf := &File{
2019-09-02 01:02:45 +03:00
pkging: fx,
info: pkging.WithName(f.info.Name(), f.info),
path: f.path,
data: f.data,
her: f.her,
2019-09-01 00:00:24 +03:00
}
return nf, nil
}