util

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidName = errors.New("invalid name: cannot be empty or '.', or contain '..' or any of these characters: " + badChars)
View Source
var KnownSiteYmlConfigFiles = []string{"_site.yml", "_site.yaml", "_bookdown.yml", "_bookdown.yaml"}

Functions

func Chdir

func Chdir(dir string) (string, error)

func GetBundleURL added in v1.1.7

func GetBundleURL(accountURL string, contentID types.ContentID, bundleID types.BundleID) string

func GetDashboardURL added in v1.1.7

func GetDashboardURL(accountURL string, contentID types.ContentID) string

func GetDirectURL added in v1.1.7

func GetDirectURL(accountURL string, contentID types.ContentID) string

func GetListOfPossibleURLs added in v1.2.0

func GetListOfPossibleURLs(accountURL string) ([]string, error)

func GetLogsURL added in v1.1.7

func GetLogsURL(accountURL string, contentID types.ContentID) string

func GetRequestBody

func GetRequestBody(req *http.Request) ([]byte, error)

GetRequestBody reads the body of an http client request. It returns the body and makes req.Body ready to read again.

func IsPythonEnvironmentDir

func IsPythonEnvironmentDir(path AbsolutePath) bool

func IsRenvLibraryDir

func IsRenvLibraryDir(path AbsolutePath) bool

func Map added in v1.1.5

func Map[T any](fn func(T) T, list []T) []T

func NewMockPathLooker

func NewMockPathLooker() *mockPathLooker

func NewSymlinkWalker

func NewSymlinkWalker(walker Walker, log logging.Logger) *symlinkWalker

NewSymlinkWalker creates a SymlinkWalker, an instance of the Walker interface that resolves symlinks before passing info to the callback function.

func NormalizeServerURL

func NormalizeServerURL(serverURL string) (string, error)

func RandomBytes

func RandomBytes(n int) ([]byte, error)

func RandomString

func RandomString(n int) (string, error)

func ReadTOMLFile

func ReadTOMLFile(path AbsolutePath, dest any) error

func RemoveDuplicates

func RemoveDuplicates[T comparable](list []T) []T

func URLJoin

func URLJoin(a, b string) string

URLJoin joins two url parts with a slash.

func ValidateFilename

func ValidateFilename(name string) error

Types

type AbsolutePath

type AbsolutePath struct {
	Path
}

func Getwd

func Getwd(fs afero.Fs) (AbsolutePath, error)

func NewAbsolutePath

func NewAbsolutePath(path string, fs afero.Fs) AbsolutePath

func UserHomeDir

func UserHomeDir(fs afero.Fs) (AbsolutePath, error)

func (AbsolutePath) Abs

func (p AbsolutePath) Abs() (AbsolutePath, error)

func (AbsolutePath) Clean

func (p AbsolutePath) Clean() AbsolutePath

func (AbsolutePath) Dir

func (p AbsolutePath) Dir() AbsolutePath

func (AbsolutePath) Glob

func (p AbsolutePath) Glob(pattern string) ([]AbsolutePath, error)

func (AbsolutePath) Join

func (p AbsolutePath) Join(other ...string) AbsolutePath

func (AbsolutePath) SafeJoin

func (p AbsolutePath) SafeJoin(other ...string) (AbsolutePath, error)

func (AbsolutePath) Split

func (p AbsolutePath) Split() (AbsolutePath, string)

func (AbsolutePath) Walk

func (p AbsolutePath) Walk(fn AbsoluteWalkFunc) error

func (AbsolutePath) WithFs

func (p AbsolutePath) WithFs(fs afero.Fs) AbsolutePath

func (AbsolutePath) WithoutExt added in v1.1.6

func (p AbsolutePath) WithoutExt() AbsolutePath

type AbsoluteWalkFunc

type AbsoluteWalkFunc func(path AbsolutePath, info fs.FileInfo, err error) error

type DecodeError

type DecodeError struct {
	File    string `mapstructure:"file"`
	Line    int    `mapstructure:"line"`
	Column  int    `mapstructure:"column"`
	Key     string `mapstructure:"key"`
	Problem string `mapstructure:"problem"`
}

DecodeError mirrors toml.DecodeError, with exported fields

func (*DecodeError) Error

func (e *DecodeError) Error() string

type FSWalker

type FSWalker struct{}

func (FSWalker) Walk

func (w FSWalker) Walk(root AbsolutePath, fn AbsoluteWalkFunc) error

type FilteredFS

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

func NewFilteredFS

func NewFilteredFS(base afero.Fs, paths []string) *FilteredFS

func (*FilteredFS) Chmod

func (fs *FilteredFS) Chmod(name string, mode os.FileMode) error

func (*FilteredFS) Chown

func (fs *FilteredFS) Chown(name string, uid, gid int) error

func (*FilteredFS) Chtimes

func (fs *FilteredFS) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*FilteredFS) Create

func (fs *FilteredFS) Create(name string) (afero.File, error)

func (*FilteredFS) Mkdir

func (fs *FilteredFS) Mkdir(name string, perm os.FileMode) error

func (*FilteredFS) MkdirAll

func (fs *FilteredFS) MkdirAll(path string, perm os.FileMode) error

func (*FilteredFS) Name

func (fs *FilteredFS) Name() string

func (*FilteredFS) Open

func (fs *FilteredFS) Open(name string) (afero.File, error)

func (*FilteredFS) OpenFile

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

func (*FilteredFS) Remove

func (fs *FilteredFS) Remove(name string) error

func (*FilteredFS) RemoveAll

func (fs *FilteredFS) RemoveAll(path string) error

func (*FilteredFS) Rename

func (fs *FilteredFS) Rename(oldname, newname string) error

func (*FilteredFS) Stat

func (fs *FilteredFS) Stat(name string) (os.FileInfo, error)

type Nothing

type Nothing struct{}

type Path

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

func DirFromPath

func DirFromPath(path Path) (Path, error)

DirFromPath returns the directory associated with the specified path. If the path is a directory, it is returned. Otherwise, the parent dir of the path is returned.

func NewPath

func NewPath(path string, fs afero.Fs) Path

func PathFromEnvironment

func PathFromEnvironment(envVar string, fs afero.Fs) Path

func PathFromSlash

func PathFromSlash(fs afero.Fs, path string) Path

func (Path) Abs

func (p Path) Abs() (AbsolutePath, error)

func (Path) Base

func (p Path) Base() string

func (Path) Chmod

func (p Path) Chmod(mode os.FileMode) error

func (Path) Chown

func (p Path) Chown(uid int, gid int) error

func (Path) Chtimes

func (p Path) Chtimes(atime, mtime time.Time) error

func (Path) Clean

func (p Path) Clean() Path

func (Path) Create

func (p Path) Create() (afero.File, error)

func (Path) Dir

func (p Path) Dir() Path

func (Path) DirExists

func (p Path) DirExists() (bool, error)

func (Path) Exists

func (p Path) Exists() (bool, error)

func (Path) Ext

func (p Path) Ext() string

func (Path) Fs

func (p Path) Fs() afero.Fs

func (Path) Glob

func (p Path) Glob(pattern string) ([]Path, error)

func (Path) HasSuffix

func (p Path) HasSuffix(suffix string) bool

func (Path) IsAbs

func (p Path) IsAbs() bool

func (Path) IsDir

func (p Path) IsDir() (bool, error)

func (Path) IsEmpty

func (p Path) IsEmpty() (bool, error)

func (Path) IsLocal

func (p Path) IsLocal() bool

func (Path) Join

func (p Path) Join(other ...string) Path

func (Path) LstatIfPossible

func (p Path) LstatIfPossible() (fs.FileInfo, bool, error)

func (Path) MarshalJSON

func (p Path) MarshalJSON() ([]byte, error)

func (Path) Match

func (p Path) Match(pattern string) (matched bool, err error)

func (Path) Mkdir

func (p Path) Mkdir(perm os.FileMode) error

func (Path) MkdirAll

func (p Path) MkdirAll(perm os.FileMode) error

func (Path) Open

func (p Path) Open() (afero.File, error)

func (Path) OpenFile

func (p Path) OpenFile(flag int, perm os.FileMode) (afero.File, error)

func (Path) ReadDir

func (p Path) ReadDir() ([]os.FileInfo, error)

func (Path) ReadDirNames added in v1.1.6

func (p Path) ReadDirNames() ([]string, error)

func (Path) ReadFile

func (p Path) ReadFile() ([]byte, error)

func (Path) ReadlinkIfPossible

func (p Path) ReadlinkIfPossible() (Path, error)

func (Path) Rel

func (p Path) Rel(basepath AbsolutePath) (RelativePath, error)

func (Path) Remove

func (p Path) Remove() error

func (Path) RemoveAll

func (p Path) RemoveAll() error

func (Path) Rename

func (p Path) Rename(newPath Path) error

func (Path) RenameStr

func (p Path) RenameStr(newName string) error

func (Path) SafeJoin

func (p Path) SafeJoin(other ...string) (Path, error)

func (Path) Split

func (p Path) Split() (Path, string)

func (Path) SplitList

func (p Path) SplitList() []string

func (Path) Stat

func (p Path) Stat() (os.FileInfo, error)

func (Path) String

func (p Path) String() string

func (Path) SymlinkIfPossible

func (p Path) SymlinkIfPossible(target Path) error

func (Path) TempDir

func (p Path) TempDir(prefix string) (Path, error)

func (Path) TempFile

func (p Path) TempFile(pattern string) (afero.File, error)

func (Path) ToSlash

func (p Path) ToSlash() string

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(data []byte) error

func (*Path) UnmarshalText

func (p *Path) UnmarshalText(data []byte) error

func (Path) VolumeName

func (p Path) VolumeName(path string) string

func (Path) Walk

func (p Path) Walk(fn WalkFunc) error

func (Path) WithFs

func (p Path) WithFs(fs afero.Fs) Path

func (Path) WithoutExt added in v1.1.6

func (p Path) WithoutExt() Path

func (Path) WriteFile

func (p Path) WriteFile(data []byte, perm os.FileMode) error

func (Path) WriteReader

func (p Path) WriteReader(r io.Reader) error

type PathLooker

type PathLooker interface {
	LookPath(name string) (string, error)
}

func NewPathLooker

func NewPathLooker() PathLooker

type RelativePath

type RelativePath struct {
	Path
}

func NewRelativePath

func NewRelativePath(path string, fs afero.Fs) RelativePath

func (RelativePath) Clean

func (p RelativePath) Clean() RelativePath

func (RelativePath) Dir

func (p RelativePath) Dir() RelativePath

func (RelativePath) Glob

func (p RelativePath) Glob(pattern string) ([]RelativePath, error)

func (RelativePath) Join

func (p RelativePath) Join(other ...string) RelativePath

func (RelativePath) Rel

func (p RelativePath) Rel(basepath AbsolutePath) (RelativePath, error)

func (RelativePath) SafeJoin

func (p RelativePath) SafeJoin(other ...string) (RelativePath, error)

func (RelativePath) Split

func (p RelativePath) Split() (RelativePath, string)

func (RelativePath) Walk

func (p RelativePath) Walk(fn RelativeWalkFunc) error

func (RelativePath) WithFs

func (p RelativePath) WithFs(fs afero.Fs) RelativePath

func (RelativePath) WithoutExt added in v1.1.6

func (p RelativePath) WithoutExt() RelativePath

type RelativeWalkFunc

type RelativeWalkFunc func(path RelativePath, info fs.FileInfo, err error) error

type TarWriter

type TarWriter interface {
	io.WriteCloser
	WriteHeader(*tar.Header) error
}

type WalkFunc

type WalkFunc func(path Path, info fs.FileInfo, err error) error

type Walker

type Walker interface {
	Walk(root AbsolutePath, fn AbsoluteWalkFunc) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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