Documentation ¶
Overview ¶
Package gres provides resource management and packing/unpacking feature between files and bytes.
Index ¶
- Constants
- func Add(content string, prefix ...string) error
- func Contains(path string) bool
- func Dump()
- func Export(src, dst string, option ...ExportOption) error
- func GetContent(path string) []byte
- func IsEmpty() bool
- func Load(path string, prefix ...string) error
- func Pack(srcPaths string, keyPrefix ...string) ([]byte, error)
- func PackToFile(srcPaths, dstPath string, keyPrefix ...string) error
- func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) error
- type ExportOption
- type File
- func Get(path string) *File
- func GetWithIndex(path string, indexFiles []string) *File
- func ScanDir(path string, pattern string, recursive ...bool) []*File
- func ScanDirFile(path string, pattern string, recursive ...bool) []*File
- func Unpack(path string) ([]*File, error)
- func UnpackContent(content string) ([]*File, error)
- func (f *File) Close() error
- func (f *File) Content() []byte
- func (f *File) FileInfo() os.FileInfo
- func (f *File) MarshalJSON() ([]byte, error)
- func (f *File) Name() string
- func (f *File) Open() (io.ReadCloser, error)
- func (f *File) Read(b []byte) (n int, err error)
- func (f *File) Readdir(count int) ([]os.FileInfo, error)
- func (f *File) Seek(offset int64, whence int) (n int64, err error)
- func (f *File) Stat() (os.FileInfo, error)
- type Resource
- func (r *Resource) Add(content string, prefix ...string) error
- func (r *Resource) Contains(path string) bool
- func (r *Resource) Dump()
- func (r *Resource) Export(src, dst string, option ...ExportOption) error
- func (r *Resource) Get(path string) *File
- func (r *Resource) GetContent(path string) []byte
- func (r *Resource) GetWithIndex(path string, indexFiles []string) *File
- func (r *Resource) IsEmpty() bool
- func (r *Resource) Load(path string, prefix ...string) error
- func (r *Resource) ScanDir(path string, pattern string, recursive ...bool) []*File
- func (r *Resource) ScanDirFile(path string, pattern string, recursive ...bool) []*File
Constants ¶
const (
// DefaultName default group name for instance usage.
DefaultName = "default"
)
const (
// Separator for directories.
Separator = "/"
)
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add unpacks and adds the `content` into the default resource object. The unnecessary parameter `prefix` indicates the prefix for each file storing into current resource object.
func Export ¶
func Export(src, dst string, option ...ExportOption) error
Export exports and saves specified path `src` and all its sub files to specified system path `dst` recursively.
func GetContent ¶
GetContent directly returns the content of `path` in default resource object.
func IsEmpty ¶
func IsEmpty() bool
IsEmpty checks and returns whether the resource manager is empty.
func Load ¶
Load loads, unpacks and adds the data from `path` into the default resource object. The unnecessary parameter `prefix` indicates the prefix for each file storing into current resource object.
func Pack ¶
Pack packs the path specified by `srcPaths` into bytes. The unnecessary parameter `keyPrefix` indicates the prefix for each file packed into the result bytes.
Note that parameter `srcPaths` supports multiple paths join with ','.
func PackToFile ¶
PackToFile packs the path specified by `srcPaths` to target file `dstPath`. The unnecessary parameter `keyPrefix` indicates the prefix for each file packed into the result bytes.
Note that parameter `srcPaths` supports multiple paths join with ','.
func PackToGoFile ¶
PackToGoFile packs the path specified by `srcPaths` to target go file `goFilePath` with given package name `pkgName`.
The unnecessary parameter `keyPrefix` indicates the prefix for each file packed into the result bytes.
Note that parameter `srcPaths` supports multiple paths join with ','.
Types ¶
type ExportOption ¶
type ExportOption struct {
RemovePrefix string // Remove the prefix of file name from resource.
}
ExportOption is the option for function Export.
type File ¶
type File struct {
// contains filtered or unexported fields
}
func GetWithIndex ¶
GetWithIndex searches file with `path`, if the file is directory it then does index files searching under this directory.
GetWithIndex is usually used for http static file service.
func ScanDir ¶
ScanDir returns the files under the given path, the parameter `path` should be a folder type.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
It scans directory recursively if given parameter `recursive` is true.
func ScanDirFile ¶
ScanDirFile returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
Note that it returns only files, exclusive of directories.
func UnpackContent ¶
UnpackContent unpacks the content to []*File.
func (*File) MarshalJSON ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*File) Open ¶
func (f *File) Open() (io.ReadCloser, error)
Open returns a ReadCloser that provides access to the File's contents. Multiple files may be read concurrently.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
func Instance ¶
Instance returns an instance of Resource. The parameter `name` is the name for the instance.
func (*Resource) Add ¶
Add unpacks and adds the `content` into current resource object. The unnecessary parameter `prefix` indicates the prefix for each file storing into current resource object.
func (*Resource) Export ¶
func (r *Resource) Export(src, dst string, option ...ExportOption) error
Export exports and saves specified path `srcPath` and all its sub files to specified system path `dstPath` recursively.
func (*Resource) GetContent ¶
GetContent directly returns the content of `path`.
func (*Resource) GetWithIndex ¶
GetWithIndex searches file with `path`, if the file is directory it then does index files searching under this directory.
GetWithIndex is usually used for http static file service.
func (*Resource) Load ¶
Load loads, unpacks and adds the data from `path` into current resource object. The unnecessary parameter `prefix` indicates the prefix for each file storing into current resource object.
func (*Resource) ScanDir ¶
ScanDir returns the files under the given path, the parameter `path` should be a folder type.
The pattern parameter `pattern` supports multiple file name patterns, using the ',' symbol to separate multiple patterns.
It scans directory recursively if given parameter `recursive` is true.
Note that the returned files does not contain given parameter `path`.
func (*Resource) ScanDirFile ¶
ScanDirFile returns all sub-files with absolute paths of given `path`, It scans directory recursively if given parameter `recursive` is true.
Note that it returns only files, exclusive of directories.