pkger/http.go

55 lines
758 B
Go
Raw Normal View History

2019-07-31 00:21:26 +03:00
package pkger
2019-08-09 04:51:58 +03:00
import (
"net/http"
"path"
)
func (f *File) Open(name string) (http.File, error) {
pt, err := Parse(name)
if err != nil {
return nil, err
}
if pt == f.path {
return f, nil
}
pt.Name = path.Join(f.Path().Name, pt.Name)
2019-08-09 05:35:01 +03:00
di, err := Open(pt.String())
2019-08-09 04:51:58 +03:00
if err != nil {
2019-08-09 22:30:12 +03:00
return nil, err
}
fi, err := di.Stat()
if err != nil {
return nil, err
}
if fi.IsDir() {
di.parent = f.path
2019-08-09 04:51:58 +03:00
}
return di, nil
}
2019-08-09 05:35:01 +03:00
func Open(name string) (*File, error) {
pt, err := Parse(name)
if err != nil {
return nil, err
}
dubeg("Open", pt.String())
f, ok := filesCache.Load(pt)
2019-08-09 04:51:58 +03:00
if !ok {
2019-08-09 05:35:01 +03:00
return openDisk(pt)
2019-08-09 04:51:58 +03:00
}
nf := &File{
2019-08-09 22:30:12 +03:00
info: WithName(f.info.Name(), f.info),
2019-08-09 04:51:58 +03:00
path: f.path,
data: f.data,
her: f.her,
}
return nf, nil
}