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)deprecated
- func PackToFile(srcPaths, dstPath string, keyPrefix ...string) errordeprecated
- func PackToFileWithOption(srcPaths, dstPath string, option Option) error
- func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) errordeprecated
- func PackToGoFileWithOption(srcPath, goFilePath, pkgName string, option Option) error
- func PackWithOption(srcPaths string, option Option) ([]byte, 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) Export(dst string, option ...ExportOption) error
- 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 Option
- 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
deprecated
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 ','.
Deprecated: use PackWithOption instead.
func PackToFile
deprecated
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 ','.
Deprecated: use PackToFileWithOption instead.
func PackToFileWithOption ¶ added in v2.2.1
PackToFileWithOption packs the path specified by `srcPaths` to target file `dstPath`.
Note that parameter `srcPaths` supports multiple paths join with ','.
func PackToGoFile
deprecated
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 ','.
Deprecated: use PackToGoFileWithOption instead.
func PackToGoFileWithOption ¶ added in v2.2.1
PackToGoFileWithOption packs the path specified by `srcPaths` to target go file `goFilePath` with given package name `pkgName`.
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) Export ¶ added in v2.1.2
func (f *File) Export(dst string, option ...ExportOption) error
Export exports and saves all its sub files to specified system path `dst` recursively.
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 Option ¶ added in v2.2.1
type Option struct { Prefix string // The file path prefix for each file item in resource manager. KeepPath bool // Keep the passed path when packing, usually for relative path. }
Option contains the extra options for Pack functions.
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.