Documentation ¶
Overview ¶
Package gres 提供了资源管理功能以及文件和字节之间的打包/解包功能。
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 PackToFileWithOption(srcPaths, dstPath string, option Option) error
- func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) error
- 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 默认的实例使用组名。
DefaultName = "default"
)
const (
// 目录分隔符。
Separator = "/"
)
Variables ¶
This section is empty.
Functions ¶
func Export ¶
func Export(src, dst string, option ...ExportOption) error
Export 函数会递归地导出并保存指定路径 `src` 及其所有子文件到指定的系统路径 `dst`。
func Pack ¶
Pack 将由 `srcPaths` 指定的路径打包成字节形式。 不必要的参数 `keyPrefix` 表示每个文件被打包到结果字节中时的前缀。
注意,参数 `srcPaths` 支持使用 ',' 连接的多个路径。
已弃用:请改用 PackWithOption。
func PackToFile ¶
PackToFile 将由`srcPaths`指定的路径打包到目标文件`dstPath`中。 不必要的参数`keyPrefix`表示每个被打包到结果字节中的文件前缀。
注意,参数`srcPaths`支持使用','连接的多个路径。
已弃用:请改用PackToFileWithOption。
func PackToFileWithOption ¶
PackToFileWithOption 将由 `srcPaths` 指定的路径打包到目标文件 `dstPath`。
注意,参数 `srcPaths` 支持通过 ',' 连接的多个路径。
func PackToGoFile ¶
PackToGoFile 将由 `srcPaths` 指定的路径打包到目标 Go 文件 `goFilePath`, 并使用给定的包名 `pkgName`。
非必需参数 `keyPrefix` 表示每个打包进结果字节流文件的前缀。
注意,参数 `srcPaths` 支持以 ',' 连接的多个路径。
已弃用:请改用 PackToGoFileWithOption。
func PackToGoFileWithOption ¶
PackToGoFileWithOption 根据指定的 `srcPaths` 路径将文件打包到目标 Go 文件 `goFilePath`, 同时使用给定的包名 `pkgName`。
注意,参数 `srcPaths` 支持通过 ',' 连接多个路径。
Types ¶
type ExportOption ¶
type ExportOption struct {
RemovePrefix string // 从资源中移除文件名前缀
}
ExportOption 是函数 Export 的选项。
type File ¶
type File struct {
// contains filtered or unexported fields
}
func GetWithIndex ¶
GetWithIndex 搜索指定 `path` 的文件,如果该文件是一个目录, 则进一步在该目录下进行索引文件的搜索。
GetWithIndex 通常用于 HTTP 静态文件服务。
func ScanDir ¶
ScanDir 返回给定路径下的文件,参数 `path` 应为文件夹类型。
参数 `pattern` 支持多个文件名模式, 使用 ',' 符号分隔多个模式。
若给定的参数 `recursive` 为 true,则会递归扫描目录。
func ScanDirFile ¶
ScanDirFile 返回给定 `path` 下所有子文件的绝对路径, 若给定参数 `recursive` 为 true,则会递归扫描目录。
注意,该函数仅返回文件,不包括目录。
func UnpackContent ¶
UnpackContent 解析内容到 []*File 类型的切片。
func (*File) Export ¶
func (f *File) Export(dst string, option ...ExportOption) error
Export 递归地将所有子文件导出并保存到指定的系统路径 `dst`。
func (File) MarshalJSON ¶
MarshalJSON 实现了 json.Marshal 接口所需的 MarshalJSON 方法。
func (*File) Open ¶
func (f *File) Open() (io.ReadCloser, error)
Open 函数返回一个 ReadCloser 类型的对象,该对象提供了对文件内容的访问权限。 允许同时读取多个文件。
type Option ¶
type Option struct { Prefix string // 在资源管理器中,每个文件项的文件路径前缀。 KeepPath bool // 在打包时保留传递的路径,通常用于相对路径。 }
Option 包含 Pack 函数的额外选项。
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
func (*Resource) Export ¶
func (r *Resource) Export(src, dst string, option ...ExportOption) error
Export 递归地导出并保存指定路径`srcPath`及其所有子文件到指定系统路径`dstPath`。
func (*Resource) GetContent ¶
GetContent直接返回`path`的内容。
func (*Resource) GetWithIndex ¶
GetWithIndex 搜索指定 `path` 的文件,如果该文件是一个目录, 则进一步在该目录下进行索引文件的搜索。
GetWithIndex 通常用于 HTTP 静态文件服务。