os

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetScriptArgs added in v1.1.0

func GetScriptArgs() []string

if risor is started from the comand line and args are passed in, this is is how the to get them

func MassagePathError

func MassagePathError(basePath string, err error) error

MassagePathError transforms a fs.PathError into a new one with the base path removed from the Path field.

func ResolvePath

func ResolvePath(base, path, op string) (string, error)

ResolvePath resolves a path relative to a base path. An error is returned if the path is invalid.

func SetScriptArgs added in v1.1.0

func SetScriptArgs(args []string)

if risor is started from the comand line and args are passed in, this is is how the to tell the os package about them

func WithOS

func WithOS(ctx context.Context, osObj OS) context.Context

WithOS adds an OS to the context. Subsequently, when this context is present in the invocation of Risor builtins, this OS will be used for all related functionality.

Types

type DirEntry

type DirEntry interface {
	fs.DirEntry
	HasInfo() bool
}

type DirEntryWrapper

type DirEntryWrapper struct {
	fs.DirEntry
}

func (*DirEntryWrapper) HasInfo

func (de *DirEntryWrapper) HasInfo() bool

type ExitHandler

type ExitHandler func(int)

type FS

type FS interface {
	Create(name string) (File, error)
	Mkdir(name string, perm FileMode) error
	MkdirAll(path string, perm FileMode) error
	Open(name string) (File, error)
	ReadFile(name string) ([]byte, error)
	Remove(name string) error
	RemoveAll(path string) error
	Rename(oldpath, newpath string) error
	Stat(name string) (FileInfo, error)
	Symlink(oldname, newname string) error
	WriteFile(name string, data []byte, perm FileMode) error
	ReadDir(name string) ([]DirEntry, error)
	WalkDir(root string, fn WalkDirFunc) error
}

type File

type File interface {
	fs.File
	io.Writer
}

type FileInfo

type FileInfo = fs.FileInfo

type FileMode

type FileMode = fs.FileMode

type GenericDirEntry

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

func NewDirEntry

func NewDirEntry(opts GenericDirEntryOpts) *GenericDirEntry

func (*GenericDirEntry) HasInfo

func (de *GenericDirEntry) HasInfo() bool

func (*GenericDirEntry) Info

func (de *GenericDirEntry) Info() (FileInfo, error)

func (*GenericDirEntry) IsDir

func (de *GenericDirEntry) IsDir() bool

func (*GenericDirEntry) Name

func (de *GenericDirEntry) Name() string

func (*GenericDirEntry) Type

func (de *GenericDirEntry) Type() FileMode

type GenericDirEntryOpts

type GenericDirEntryOpts struct {
	Name string
	Mode FileMode
	Info *GenericFileInfo
}

type GenericFileInfo

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

func NewFileInfo

func NewFileInfo(opts GenericFileInfoOpts) *GenericFileInfo

func (*GenericFileInfo) IsDir

func (fi *GenericFileInfo) IsDir() bool

func (*GenericFileInfo) ModTime

func (fi *GenericFileInfo) ModTime() time.Time

func (*GenericFileInfo) Mode

func (fi *GenericFileInfo) Mode() FileMode

func (*GenericFileInfo) Name

func (fi *GenericFileInfo) Name() string

func (*GenericFileInfo) Size

func (fi *GenericFileInfo) Size() int64

func (*GenericFileInfo) Sys

func (fi *GenericFileInfo) Sys() interface{}

type GenericFileInfoOpts

type GenericFileInfoOpts struct {
	Name    string
	Size    int64
	Mode    FileMode
	ModTime time.Time
	IsDir   bool
}

type InMemoryFile added in v0.10.0

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

func NewInMemoryFile added in v0.10.0

func NewInMemoryFile(data []byte) *InMemoryFile

func (*InMemoryFile) Bytes added in v0.10.0

func (f *InMemoryFile) Bytes() []byte

func (*InMemoryFile) Close added in v0.10.0

func (f *InMemoryFile) Close() error

func (*InMemoryFile) Read added in v0.10.0

func (f *InMemoryFile) Read(p []byte) (n int, err error)

func (*InMemoryFile) ReadAt added in v0.10.0

func (f *InMemoryFile) ReadAt(p []byte, off int64) (n int, err error)

func (*InMemoryFile) Seek added in v0.10.0

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

func (*InMemoryFile) Stat added in v0.10.0

func (f *InMemoryFile) Stat() (FileInfo, error)

func (*InMemoryFile) Write added in v0.10.0

func (f *InMemoryFile) Write(p []byte) (n int, err error)

type Mount

type Mount struct {
	Source FS
	Target string
	Type   string
}

type NilFile added in v0.10.0

type NilFile struct{}

func (*NilFile) Close added in v0.10.0

func (f *NilFile) Close() error

func (*NilFile) Read added in v0.10.0

func (f *NilFile) Read(p []byte) (n int, err error)

func (*NilFile) ReadAt added in v0.10.0

func (f *NilFile) ReadAt(p []byte, off int64) (n int, err error)

func (*NilFile) Seek added in v0.10.0

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

func (*NilFile) Stat added in v0.10.0

func (f *NilFile) Stat() (FileInfo, error)

func (*NilFile) Write added in v0.10.0

func (f *NilFile) Write(p []byte) (n int, err error)

type OS

type OS interface {
	FS
	Args() []string
	Chdir(dir string) error
	Environ() []string
	Exit(code int)
	Getenv(key string) string
	Getpid() int
	Getuid() int
	Getwd() (dir string, err error)
	Hostname() (name string, err error)
	LookupEnv(key string) (string, bool)
	MkdirTemp(dir, pattern string) (string, error)
	Setenv(key, value string) error
	TempDir() string
	Unsetenv(key string) error
	UserCacheDir() (string, error)
	UserConfigDir() (string, error)
	UserHomeDir() (string, error)
	Stdin() File
	Stdout() File
}

func GetDefaultOS added in v0.10.0

func GetDefaultOS(ctx context.Context) OS

GetDefaultOS returns the OS from the context, if it exists. Otherwise, it returns a new SimpleOS.

func GetOS

func GetOS(ctx context.Context) (OS, bool)

GetOS returns the OS from the context, if it exists.

type Option

type Option func(*VirtualOS)

Option is a configuration function for a Virtual Machine.

func WithArgs added in v1.1.0

func WithArgs(args []string) Option

set the args passed to the os package for os.args()

func WithCwd

func WithCwd(cwd string) Option

WithCwd sets the current working directory.

func WithEnvironment

func WithEnvironment(env map[string]string) Option

WithEnvironment sets the user home directory.

func WithExitHandler

func WithExitHandler(exitHandler ExitHandler) Option

WithExitHandler sets the exit handler.

func WithHostname

func WithHostname(hostname string) Option

WithHostname sets the hostname.

func WithMounts

func WithMounts(mounts map[string]*Mount) Option

WithMounts sets the mounts.

func WithPid

func WithPid(pid int) Option

WithPid sets the process ID.

func WithStdin added in v0.10.0

func WithStdin(stdin File) Option

WithStdin sets the stdin.

func WithStdout added in v0.10.0

func WithStdout(stdout File) Option

WithStdout sets the stdout.

func WithTmp

func WithTmp(tmp string) Option

WithTmp sets the path to the temporary directory.

func WithUid

func WithUid(uid int) Option

WithUid sets the user ID.

func WithUserCacheDir

func WithUserCacheDir(dir string) Option

WithUserCacheDir sets the user cache directory.

func WithUserConfigDir

func WithUserConfigDir(dir string) Option

WithUserConfigDir sets the user config directory.

func WithUserHomeDir

func WithUserHomeDir(dir string) Option

WithUserHomeDir sets the user home directory.

type ReadDirFile

type ReadDirFile = fs.ReadDirFile

type SimpleOS

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

func NewSimpleOS

func NewSimpleOS(ctx context.Context) *SimpleOS

func (*SimpleOS) Args added in v1.1.0

func (osObj *SimpleOS) Args() []string

func (*SimpleOS) Chdir

func (osObj *SimpleOS) Chdir(dir string) error

func (*SimpleOS) Create

func (osObj *SimpleOS) Create(name string) (File, error)

func (*SimpleOS) Environ

func (osObj *SimpleOS) Environ() []string

func (*SimpleOS) Exit

func (osObj *SimpleOS) Exit(code int)

func (*SimpleOS) Getenv

func (osObj *SimpleOS) Getenv(key string) string

func (*SimpleOS) Getpid

func (osObj *SimpleOS) Getpid() int

func (*SimpleOS) Getuid

func (osObj *SimpleOS) Getuid() int

func (*SimpleOS) Getwd

func (osObj *SimpleOS) Getwd() (string, error)

func (*SimpleOS) Hostname

func (osObj *SimpleOS) Hostname() (string, error)

func (*SimpleOS) LookupEnv

func (osObj *SimpleOS) LookupEnv(key string) (string, bool)

func (*SimpleOS) Mkdir

func (osObj *SimpleOS) Mkdir(name string, perm FileMode) error

func (*SimpleOS) MkdirAll

func (osObj *SimpleOS) MkdirAll(path string, perm FileMode) error

func (*SimpleOS) MkdirTemp

func (osObj *SimpleOS) MkdirTemp(dir, pattern string) (string, error)

func (*SimpleOS) Open

func (osObj *SimpleOS) Open(name string) (File, error)

func (*SimpleOS) ReadDir

func (osObj *SimpleOS) ReadDir(name string) ([]DirEntry, error)

func (*SimpleOS) ReadFile

func (osObj *SimpleOS) ReadFile(name string) ([]byte, error)

func (*SimpleOS) Remove

func (osObj *SimpleOS) Remove(name string) error

func (*SimpleOS) RemoveAll added in v0.13.0

func (osObj *SimpleOS) RemoveAll(path string) error

func (*SimpleOS) Rename

func (osObj *SimpleOS) Rename(oldpath, newpath string) error

func (*SimpleOS) Setenv

func (osObj *SimpleOS) Setenv(key, value string) error

func (*SimpleOS) Stat

func (osObj *SimpleOS) Stat(name string) (os.FileInfo, error)

func (*SimpleOS) Stdin added in v0.10.0

func (osObj *SimpleOS) Stdin() File

func (*SimpleOS) Stdout added in v0.10.0

func (osObj *SimpleOS) Stdout() File
func (osObj *SimpleOS) Symlink(oldname, newname string) error

func (*SimpleOS) TempDir

func (osObj *SimpleOS) TempDir() string

func (*SimpleOS) Unsetenv

func (osObj *SimpleOS) Unsetenv(key string) error

func (*SimpleOS) UserCacheDir

func (osObj *SimpleOS) UserCacheDir() (string, error)

func (*SimpleOS) UserConfigDir

func (osObj *SimpleOS) UserConfigDir() (string, error)

func (*SimpleOS) UserHomeDir

func (osObj *SimpleOS) UserHomeDir() (string, error)

func (*SimpleOS) WalkDir added in v1.2.0

func (osObj *SimpleOS) WalkDir(root string, fn WalkDirFunc) error

func (*SimpleOS) WriteFile

func (osObj *SimpleOS) WriteFile(name string, data []byte, perm FileMode) error

type VirtualOS

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

func NewVirtualOS

func NewVirtualOS(ctx context.Context, opts ...Option) *VirtualOS

NewVirtualOS creates a new VirtualOS configured with the given options.

func (*VirtualOS) Args added in v1.1.0

func (osObj *VirtualOS) Args() []string

func (*VirtualOS) Chdir

func (osObj *VirtualOS) Chdir(dir string) error

func (*VirtualOS) Create

func (osObj *VirtualOS) Create(name string) (File, error)

func (*VirtualOS) Environ

func (osObj *VirtualOS) Environ() []string

func (*VirtualOS) Exit

func (osObj *VirtualOS) Exit(code int)

func (*VirtualOS) Getenv

func (osObj *VirtualOS) Getenv(key string) string

func (*VirtualOS) Getpid

func (osObj *VirtualOS) Getpid() int

func (*VirtualOS) Getuid

func (osObj *VirtualOS) Getuid() int

func (*VirtualOS) Getwd

func (osObj *VirtualOS) Getwd() (string, error)

func (*VirtualOS) Hostname

func (osObj *VirtualOS) Hostname() (string, error)

func (*VirtualOS) LookupEnv

func (osObj *VirtualOS) LookupEnv(key string) (string, bool)

func (*VirtualOS) Mkdir

func (osObj *VirtualOS) Mkdir(name string, perm FileMode) error

func (*VirtualOS) MkdirAll

func (osObj *VirtualOS) MkdirAll(path string, perm FileMode) error

func (*VirtualOS) MkdirTemp

func (osObj *VirtualOS) MkdirTemp(dir, pattern string) (string, error)

func (*VirtualOS) Open

func (osObj *VirtualOS) Open(name string) (File, error)

func (*VirtualOS) ReadDir

func (osObj *VirtualOS) ReadDir(name string) ([]DirEntry, error)

func (*VirtualOS) ReadFile

func (osObj *VirtualOS) ReadFile(name string) ([]byte, error)

func (*VirtualOS) Remove

func (osObj *VirtualOS) Remove(name string) error

func (*VirtualOS) RemoveAll added in v0.13.0

func (osObj *VirtualOS) RemoveAll(path string) error

func (*VirtualOS) Rename

func (osObj *VirtualOS) Rename(oldpath, newpath string) error

func (*VirtualOS) SetArgs added in v1.1.0

func (osObj *VirtualOS) SetArgs(args []string)

a way to override or set the args passed to the os package would typically be used when risor is employed in an embedded manner

func (*VirtualOS) Setenv

func (osObj *VirtualOS) Setenv(key, value string) error

func (*VirtualOS) Stat

func (osObj *VirtualOS) Stat(name string) (os.FileInfo, error)

func (*VirtualOS) Stdin added in v0.10.0

func (osObj *VirtualOS) Stdin() File

func (*VirtualOS) Stdout added in v0.10.0

func (osObj *VirtualOS) Stdout() File
func (osObj *VirtualOS) Symlink(oldname, newname string) error

func (*VirtualOS) TempDir

func (osObj *VirtualOS) TempDir() string

func (*VirtualOS) Unsetenv

func (osObj *VirtualOS) Unsetenv(key string) error

func (*VirtualOS) UserCacheDir

func (osObj *VirtualOS) UserCacheDir() (string, error)

func (*VirtualOS) UserConfigDir

func (osObj *VirtualOS) UserConfigDir() (string, error)

func (*VirtualOS) UserHomeDir

func (osObj *VirtualOS) UserHomeDir() (string, error)

func (*VirtualOS) WalkDir added in v1.2.0

func (osObj *VirtualOS) WalkDir(root string, fn WalkDirFunc) error

func (*VirtualOS) WriteFile

func (osObj *VirtualOS) WriteFile(name string, data []byte, perm FileMode) error

type WalkDirFunc added in v1.2.0

type WalkDirFunc = fs.WalkDirFunc

Directories

Path Synopsis
s3fs module

Jump to

Keyboard shortcuts

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