lib

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

file operations (exists, isfile, etc.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(expr bool, msg string)

Assert mimics assert from other languages. It panics if the expression is false. If msg is given, it is printed as an error message.

func Contains

func Contains[T comparable](haystack []T, needle T) bool

Returns true if the element is found in the slice. Returns false if not found.

func ExecCmd

func ExecCmd(cmd string) (string, error)

func Exists

func Exists(path string) bool

Returns true if the entry (file, directory, symbolic link, etc.) exists. Returns false if the entry doesn't exist.

func Index

func Index[T comparable](haystack []T, needle T) int

Returns the index of an element. If not found, -1 is returned.

func IsDir

func IsDir(path string) bool

Is it a directory? Returns true for a directory and for a symbolic link pointing on a directory.

func IsFile

func IsFile(path string) bool

Is it a regular file? Returns true for a regular file and for a symbolic link pointing on a regular file.

func IsLink(path string) bool

Is it a symbolic link?

func MakeExecutable

func MakeExecutable(fname string) error

Make a file executable for the owner. Equivalent of "chmod u+x <file>" . You can also call it on Windows. It won't do anything, but you won't get an error either.

func Remove

func Remove[T comparable](slice []T, element T) ([]T, bool)

Removes the first occurrence of an element from a slice. The length of the returned slice will be one less if the element was found. The original slice will be modified if the element was found, but use the returned slice on the caller side. The returned boolean is true if the element was removed, and false otherwise.

func WriteSourceToFile

func WriteSourceToFile(source, fname string) bool

Create file and save source code in it. Print an error message if the file exists.

Types

This section is empty.

Jump to

Keyboard shortcuts

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