gres

package
v1.13.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package gres provides resource management and packing/unpacking feature between files and bytes.

Index

Constants

View Source
const (
	// Default group name for instance usage.
	DEFAULT_NAME = "default"
)
View Source
const (
	// Separator for directories.
	Separator = "/"
)

Variables

This section is empty.

Functions

func Add

func Add(content string, prefix ...string) error

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 Contains

func Contains(path string) bool

Contains checks whether the <path> exists in the default resource object.

func Dump

func Dump()

Dump prints the files of the default resource object.

func GetContent

func GetContent(path string) []byte

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

func Load(path string, prefix ...string) error

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

func Pack(srcPaths string, keyPrefix ...string) ([]byte, error)

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

func PackToFile(srcPaths, dstPath string, keyPrefix ...string) error

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

func PackToGoFile(srcPath, goFilePath, pkgName string, keyPrefix ...string) error

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 File

type File struct {
	// contains filtered or unexported fields
}

func Get

func Get(path string) *File

Get returns the file with given path.

func GetWithIndex

func GetWithIndex(path string, indexFiles []string) *File

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

func ScanDir(path string, pattern string, recursive ...bool) []*File

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

func ScanDirFile(path string, pattern string, recursive ...bool) []*File

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 Unpack

func Unpack(path string) ([]*File, error)

Unpack unpacks the content specified by <path> to []*File.

func UnpackContent

func UnpackContent(content string) ([]*File, error)

UnpackContent unpacks the content to []*File.

func (*File) Close

func (f *File) Close() error

Close implements Close interface of http.File.

func (*File) Content

func (f *File) Content() []byte

Content returns the content of the file.

func (*File) FileInfo

func (f *File) FileInfo() os.FileInfo

FileInfo returns an os.FileInfo for the FileHeader.

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*File) Name

func (f *File) Name() string

Name returns the name of the file.

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.

func (*File) Read

func (f *File) Read(b []byte) (n int, err error)

Read implements the io.Reader interface.

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir implements Readdir interface of http.File.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface.

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat implements Stat interface of http.File.

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

func Instance

func Instance(name ...string) *Resource

Instance returns an instance of Resource. The parameter <name> is the name for the instance.

func New

func New() *Resource

New creates and returns a new resource object.

func (*Resource) Add

func (r *Resource) Add(content string, prefix ...string) error

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) Contains

func (r *Resource) Contains(path string) bool

Contains checks whether the <path> exists in current resource object.

func (*Resource) Dump

func (r *Resource) Dump()

Dump prints the files of current resource object.

func (*Resource) Get

func (r *Resource) Get(path string) *File

Get returns the file with given path.

func (*Resource) GetContent

func (r *Resource) GetContent(path string) []byte

GetContent directly returns the content of <path>.

func (*Resource) GetWithIndex

func (r *Resource) GetWithIndex(path string, indexFiles []string) *File

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) IsEmpty

func (r *Resource) IsEmpty() bool

IsEmpty checks and returns whether the resource manager is empty.

func (*Resource) Load

func (r *Resource) Load(path string, prefix ...string) error

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

func (r *Resource) ScanDir(path string, pattern string, recursive ...bool) []*File

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

func (r *Resource) ScanDirFile(path string, pattern string, recursive ...bool) []*File

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL