assets

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileReadPerm is the permission bit given to the OS when reading files.
	FileReadPerm = 0o600
	// DirPerm is the permission bit given to teamserver/client directories.
	DirPerm = 0o700
	// FileWritePerm is the permission bit given to the OS when writing files.
	FileWritePerm = 0o644

	// FileWriteOpenMode is used when opening log files in append/create/write-only mode.
	FileWriteOpenMode = os.O_APPEND | os.O_CREATE | os.O_WRONLY
)
View Source
const (

	// DirClient is the name of the teamclient subdirectory.
	DirClient = "teamclient"
	// DirLogs subdirectory name.
	DirLogs = "logs"
	// DirConfigs subdirectory name.
	DirConfigs = "configs"

	// DirServer is the name of the teamserver subdirectory.
	DirServer = "teamserver"
	// DirCerts subdirectory name.
	DirCerts = "certs"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FS

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

FS is a filesystem abstraction for teamservers and teamclients. When either of them are configured to run in memory only, this filesystem is initialized accordingly, otherwise it will forward its calls to the on-disk filesystem.

This type currently exists because the stdlib io/fs.FS type is read-only, and that in order to provide a unique abstraction to the teamclient/server filesystems, this filesystem type adds writing methods.

func NewFileSystem

func NewFileSystem(root string, inMemory bool) *FS

NewFileSystem returns a new filesystem configured to run on disk or in-memory.

func (*FS) MkdirAll

func (f *FS) MkdirAll(path string, perm fs.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

If the filesystem is in-memory, the teamclient/server application root is trimmed from this path, if the latter contains it.

func (*FS) Open

func (f *FS) Open(name string) (fs.File, error)

Open is like fs.Open().

If the filesystem is in-memory, the teamclient/server application root is trimmed from this path, if the latter contains it.

func (*FS) OpenFile

func (f *FS) OpenFile(name string, flag int, perm fs.FileMode) (*File, error)

OpenFile is like os.OpenFile(), but returns a custom *File type implementing the io.WriteCloser interface, so that it can be written to and closed more easily.

func (*FS) ReadFile

func (f *FS) ReadFile(path string) (b []byte, err error)

ReadFile is like os.ReadFile().

func (*FS) Sub

func (f *FS) Sub(path string) (fs fs.FS, err error)

Sub returns a file system (an fs.FS) for the tree of files rooted at the directory dir, or an error if it failed. When the teamclient fs is on disk, os.Stat() and os.DirFS() are used.

If the filesystem is in-memory, the teamclient/server application root is trimmed from this path, if the latter contains it.

func (*FS) WriteFile

func (f *FS) WriteFile(path string, data []byte, perm fs.FileMode) error

WriteFile is like os.WriteFile().

type File

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

File wraps the *os.File type with some in-memory helpers, so that we can write/read to teamserver application files regardless of where they are. This should disappear if a Write() method set is added to the io/fs package.

func (*File) Close

func (f *File) Close() error

Close implements io.Closer by closing the file on the filesystem.

func (*File) Write

func (f *File) Write(data []byte) (written int, err error)

Write implements the io.Writer interface by writing data either to the file on disk, or to an in-memory file.

Jump to

Keyboard shortcuts

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