context

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 6 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Background        = context.Background
	TODO              = context.TODO
	WithCancel        = context.WithCancel
	WithCancelCause   = context.WithCancelCause
	WithDeadline      = context.WithDeadline
	WithDeadlineCause = context.WithDeadlineCause
	WithValue         = context.WithValue
	WithTimeout       = context.WithTimeout
	WithTimeoutCause  = context.WithTimeoutCause
	WithoutCancel     = context.WithoutCancel
)

Functions

func BackgroundFs

func BackgroundFs(base Fs) afero.Fs

func NewFs

func NewFs(base Fs, accessor Accessor) afero.Fs

func TodoFs

func TodoFs(base Fs) afero.Fs

Types

type Accessor

type Accessor interface {
	Context() context.Context
}

func ToAccessor

func ToAccessor[T ~func() Context](fn T) Accessor

type AccessorFs

type AccessorFs struct {
	Accessor
	Fs Fs
}

AccessorFs adapts an Fs to an afero.Fs by using the given [ContextAccessor] to source the context.Context for each operation

func (*AccessorFs) Chmod

func (a *AccessorFs) Chmod(name string, mode fs.FileMode) error

Chmod implements afero.Fs.

func (*AccessorFs) Chown

func (a *AccessorFs) Chown(name string, uid int, gid int) error

Chown implements afero.Fs.

func (*AccessorFs) Chtimes

func (a *AccessorFs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes implements afero.Fs.

func (*AccessorFs) Create

func (a *AccessorFs) Create(name string) (afero.File, error)

Create implements afero.Fs.

func (*AccessorFs) Mkdir

func (a *AccessorFs) Mkdir(name string, perm fs.FileMode) error

Mkdir implements afero.Fs.

func (*AccessorFs) MkdirAll

func (a *AccessorFs) MkdirAll(path string, perm fs.FileMode) error

MkdirAll implements afero.Fs.

func (*AccessorFs) Name

func (a *AccessorFs) Name() string

Name implements afero.Fs.

func (*AccessorFs) Open

func (a *AccessorFs) Open(name string) (afero.File, error)

Open implements afero.Fs.

func (*AccessorFs) OpenFile

func (a *AccessorFs) OpenFile(name string, flag int, perm fs.FileMode) (afero.File, error)

OpenFile implements afero.Fs.

func (*AccessorFs) Remove

func (a *AccessorFs) Remove(name string) error

Remove implements afero.Fs.

func (*AccessorFs) RemoveAll

func (a *AccessorFs) RemoveAll(path string) error

RemoveAll implements afero.Fs.

func (*AccessorFs) Rename

func (a *AccessorFs) Rename(oldname string, newname string) error

Rename implements afero.Fs.

func (*AccessorFs) Stat

func (a *AccessorFs) Stat(name string) (fs.FileInfo, error)

Stat implements afero.Fs.

type AccessorFunc

type AccessorFunc func() Context

func (AccessorFunc) Context

func (fn AccessorFunc) Context() Context

type AdapterFs

type AdapterFs struct{ Fs Fs }

AdapterFs adapts an Fs to a partial AferoFs structure. It is intended to be embedded as a utility type to satisfy an AferoFs interface with an Fs

func (*AdapterFs) ChmodContext

func (a *AdapterFs) ChmodContext(ctx Context, name string, mode fs.FileMode) error

ChmodContext implements AferoFs.

func (*AdapterFs) ChownContext

func (a *AdapterFs) ChownContext(ctx Context, name string, uid int, gid int) error

ChownContext implements AferoFs.

func (*AdapterFs) ChtimesContext

func (a *AdapterFs) ChtimesContext(ctx Context, name string, atime time.Time, mtime time.Time) error

ChtimesContext implements AferoFs.

func (*AdapterFs) CreateContext

func (a *AdapterFs) CreateContext(ctx Context, name string) (afero.File, error)

CreateContext implements AferoFs.

func (*AdapterFs) MkdirAllContext

func (a *AdapterFs) MkdirAllContext(ctx Context, path string, perm fs.FileMode) error

MkdirAllContext implements AferoFs.

func (*AdapterFs) MkdirContext

func (a *AdapterFs) MkdirContext(ctx Context, name string, perm fs.FileMode) error

MkdirContext implements AferoFs.

func (*AdapterFs) OpenContext

func (a *AdapterFs) OpenContext(ctx Context, name string) (afero.File, error)

OpenContext implements AferoFs.

func (*AdapterFs) OpenFileContext

func (a *AdapterFs) OpenFileContext(ctx Context, name string, flag int, perm fs.FileMode) (afero.File, error)

OpenFileContext implements AferoFs.

func (*AdapterFs) RemoveAllContext

func (a *AdapterFs) RemoveAllContext(ctx Context, path string) error

RemoveAllContext implements AferoFs.

func (*AdapterFs) RemoveContext

func (a *AdapterFs) RemoveContext(ctx Context, name string) error

RemoveContext implements AferoFs.

func (*AdapterFs) RenameContext

func (a *AdapterFs) RenameContext(ctx Context, oldname string, newname string) error

RenameContext implements AferoFs.

func (*AdapterFs) StatContext

func (a *AdapterFs) StatContext(ctx Context, name string) (fs.FileInfo, error)

StatContext implements AferoFs.

type AferoFs

type AferoFs interface {
	afero.Fs

	// CreateContext creates a file in the filesystem, returning the file and an
	// error, if any happens.
	CreateContext(ctx Context, name string) (File, error)

	// MkdirContext creates a directory in the filesystem, return an error if any
	// happens.
	MkdirContext(ctx Context, name string, perm os.FileMode) error

	// MkdirAllContext creates a directory path and all parents that does not exist
	// yet.
	MkdirAllContext(ctx Context, path string, perm os.FileMode) error

	// OpenContext opens a file, returning it or an error, if any happens.
	OpenContext(ctx Context, name string) (File, error)

	// OpenFileContext opens a file using the given flags and the given mode.
	OpenFileContext(ctx Context, name string, flag int, perm os.FileMode) (File, error)

	// RemoveContext removes a file identified by name, returning an error, if any
	// happens.
	RemoveContext(ctx Context, name string) error

	// RemoveAllContext removes a directory path and any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAllContext(ctx Context, path string) error

	// RenameContext renames a file.
	RenameContext(ctx Context, oldname, newname string) error

	// StatContext returns a FileInfo describing the named file, or an error, if any
	// happens.
	StatContext(ctx Context, name string) (os.FileInfo, error)

	// ChmodContext changes the mode of the named file to mode.
	ChmodContext(ctx Context, name string, mode os.FileMode) error

	// ChownContext changes the uid and gid of the named file.
	ChownContext(ctx Context, name string, uid, gid int) error

	// ChtimesContext changes the access and modification times of the named file
	ChtimesContext(ctx Context, name string, atime time.Time, mtime time.Time) error
}

AferoFs is a filesystem interface.

func Adapt

func Adapt(fs Fs, accessor Accessor) AferoFs

func Discard

func Discard(fs afero.Fs) AferoFs

type Context

type Context = context.Context

type DiscardFs

type DiscardFs struct{ afero.Fs }

DiscardFs adapts an afero.Fs to an AferoFs by ignoring the context.Context argument.

func (*DiscardFs) ChmodContext

func (a *DiscardFs) ChmodContext(ctx Context, name string, mode fs.FileMode) error

ChmodContext implements AferoFs.

func (*DiscardFs) ChownContext

func (a *DiscardFs) ChownContext(ctx Context, name string, uid int, gid int) error

ChownContext implements AferoFs.

func (*DiscardFs) ChtimesContext

func (a *DiscardFs) ChtimesContext(ctx Context, name string, atime time.Time, mtime time.Time) error

ChtimesContext implements AferoFs.

func (*DiscardFs) CreateContext

func (a *DiscardFs) CreateContext(ctx Context, name string) (afero.File, error)

CreateContext implements AferoFs.

func (*DiscardFs) MkdirAllContext

func (a *DiscardFs) MkdirAllContext(ctx Context, path string, perm fs.FileMode) error

MkdirAllContext implements AferoFs.

func (*DiscardFs) MkdirContext

func (a *DiscardFs) MkdirContext(ctx Context, name string, perm fs.FileMode) error

MkdirContext implements AferoFs.

func (*DiscardFs) OpenContext

func (a *DiscardFs) OpenContext(ctx Context, name string) (afero.File, error)

OpenContext implements AferoFs.

func (*DiscardFs) OpenFileContext

func (a *DiscardFs) OpenFileContext(ctx Context, name string, flag int, perm fs.FileMode) (afero.File, error)

OpenFileContext implements AferoFs.

func (*DiscardFs) RemoveAllContext

func (a *DiscardFs) RemoveAllContext(ctx Context, path string) error

RemoveAllContext implements AferoFs.

func (*DiscardFs) RemoveContext

func (a *DiscardFs) RemoveContext(ctx Context, name string) error

RemoveContext implements AferoFs.

func (*DiscardFs) RenameContext

func (a *DiscardFs) RenameContext(ctx Context, oldname string, newname string) error

RenameContext implements AferoFs.

func (*DiscardFs) StatContext

func (a *DiscardFs) StatContext(ctx Context, name string) (fs.FileInfo, error)

StatContext implements AferoFs.

type File

type File = afero.File

type Fs

type Fs interface {
	// Create creates a file in the filesystem, returning the file and an
	// error, if any happens.
	Create(ctx Context, name string) (File, error)

	// Mkdir creates a directory in the filesystem, return an error if any
	// happens.
	Mkdir(ctx Context, name string, perm os.FileMode) error

	// MkdirAll creates a directory path and all parents that does not exist
	// yet.
	MkdirAll(ctx Context, path string, perm os.FileMode) error

	// Open opens a file, returning it or an error, if any happens.
	Open(ctx Context, name string) (File, error)

	// OpenFile opens a file using the given flags and the given mode.
	OpenFile(ctx Context, name string, flag int, perm os.FileMode) (File, error)

	// Remove removes a file identified by name, returning an error, if any
	// happens.
	Remove(ctx Context, name string) error

	// RemoveAll removes a directory path and any children it contains. It
	// does not fail if the path does not exist (return nil).
	RemoveAll(ctx Context, path string) error

	// Rename renames a file.
	Rename(ctx Context, oldname, newname string) error

	// Stat returns a FileInfo describing the named file, or an error, if any
	// happens.
	Stat(ctx Context, name string) (os.FileInfo, error)

	// The name of this FileSystem
	Name() string

	// Chmod changes the mode of the named file to mode.
	Chmod(ctx Context, name string, mode os.FileMode) error

	// Chown changes the uid and gid of the named file.
	Chown(ctx Context, name string, uid, gid int) error

	// Chtimes changes the access and modification times of the named file
	Chtimes(ctx Context, name string, atime time.Time, mtime time.Time) error
}

Fs is a filesystem interface.

type Setter

type Setter interface {
	SetContext(context.Context)
}

type WithSetterFs

type WithSetterFs struct {
	Setter
	Fs afero.Fs
}

WithSetterFs adapts an afero.Fs to an Fs by calling [SetContext] on the given [ContextSetter] before forwarding each operation to the given afero.Fs

func (*WithSetterFs) Chmod

func (s *WithSetterFs) Chmod(ctx Context, name string, mode fs.FileMode) error

Chmod implements Fs.

func (*WithSetterFs) Chown

func (s *WithSetterFs) Chown(ctx Context, name string, uid int, gid int) error

Chown implements Fs.

func (*WithSetterFs) Chtimes

func (s *WithSetterFs) Chtimes(ctx Context, name string, atime time.Time, mtime time.Time) error

Chtimes implements Fs.

func (*WithSetterFs) Create

func (s *WithSetterFs) Create(ctx Context, name string) (afero.File, error)

Create implements Fs.

func (*WithSetterFs) Mkdir

func (s *WithSetterFs) Mkdir(ctx Context, name string, perm fs.FileMode) error

Mkdir implements Fs.

func (*WithSetterFs) MkdirAll

func (s *WithSetterFs) MkdirAll(ctx Context, path string, perm fs.FileMode) error

MkdirAll implements Fs.

func (*WithSetterFs) Name

func (s *WithSetterFs) Name() string

Name implements Fs.

func (*WithSetterFs) Open

func (s *WithSetterFs) Open(ctx Context, name string) (afero.File, error)

Open implements Fs.

func (*WithSetterFs) OpenFile

func (s *WithSetterFs) OpenFile(ctx Context, name string, flag int, perm fs.FileMode) (afero.File, error)

OpenFile implements Fs.

func (*WithSetterFs) Remove

func (s *WithSetterFs) Remove(ctx Context, name string) error

Remove implements Fs.

func (*WithSetterFs) RemoveAll

func (s *WithSetterFs) RemoveAll(ctx Context, path string) error

RemoveAll implements Fs.

func (*WithSetterFs) Rename

func (s *WithSetterFs) Rename(ctx Context, oldname string, newname string) error

Rename implements Fs.

func (*WithSetterFs) Stat

func (s *WithSetterFs) Stat(ctx Context, name string) (fs.FileInfo, error)

Stat implements Fs.

Jump to

Keyboard shortcuts

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