pathutil

package
v2.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJsonUnmarshal = errors.New("invalid json")

Functions

func IsDir

func IsDir(p string) bool

IsDir returns true if p exists and is a directory.

func IsPathError

func IsPathError(err error) bool

IsPathError returns true if err is present, and it or its cause is an os.PathError.

func MarshalJsonFile

func MarshalJsonFile(path Unknown, v interface{}) error

MarshalJsonFile marshals v into path.

func MarshalJsonFileWithDirs

func MarshalJsonFileWithDirs(path Unknown, v interface{}) error

MarshalJsonFileWithDirs creates intermediate dirs and marshals v into path.

func UnmarshalJsonFile

func UnmarshalJsonFile(path Unknown, v interface{}) error

UnmarshalJsonFile unmarshals the data at path into the pointer v.

Types

type Abs

type Abs = string

Abs is an absolute path. It's just an alias of string, to avoid casting.

func ResolvePath

func ResolvePath(base, path Unknown) (Abs, error)

ResolvePath returns path if it is an absolute path, or the abspath joined with base otherwise. Use "" for base to use the cwd, as per filepath.Abs.

func ResolvePaths

func ResolvePaths(base Unknown, paths []Unknown) ([]Abs, error)

type Absdir

type Absdir Abs

Absdir is an absolute directory.

func CallerDir

func CallerDir() Absdir

CallerDir returns the directory of the calling code.

func (Absdir) Join

func (kd Absdir) Join(elem ...string) Abs

Join treats elem as the tail of the absolute directly. AbsDir("/foo").Join("x", "y") => "/foo/x/y"

type Rel

type Rel = string

Rel is a relative path. It's just an alias of string, to avoid casting.

type Unknown

type Unknown = string

Unknown can be an absolute or relative path.

func TrimExt

func TrimExt(p Unknown) Unknown

TrimExt removes the extension from p.

Jump to

Keyboard shortcuts

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