utils

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NEW_FILE_PERM = 0644
)

Variables

This section is empty.

Functions

func AppendContents

func AppendContents(filename, content string) error

AppendContents appends the contents of the string to filename. AppendContents is equivalent to AppendString.

func AppendString

func AppendString(filename, content string) error

AppendString appends the contents of the string to filename.

func Basename

func Basename(path string) string

Basename returns the last element of path

func Chmod

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

Chmod changes the mode of the named file to mode.

func Chown

func Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file.

func Contains

func Contains(arr []string, item string) bool

func Copy

func Copy(source, dest string) (err error)

Copy makes a copy of the file source to dest.

func Dirname

func Dirname(path string) string

Dirname returns all but the last element of path, typically the path's directory

func Exec

func Exec(name string, arg ...string) (string, error)

Exec runs the command and returns its standard output as string

func Exists

func Exists(filename string) (bool, error)

Exists checks if the given filename exists

func Extname

func Extname(path string) string

Extname returns the file name extension used by path

func GetContents

func GetContents(filename string) (string, error)

GetContents reads the file named by filename and returns the contents as string. GetContents is equivalent to ReadString.

func Md5

func Md5(filename string) (string, error)

Md5 returns a MD5 hash of file

func Min

func Min(a, b int) int

func Mkdir

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

Mkdir creates a new directory with the specified name and permission bits.

func MkdirAll

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

MkdirAll creates a directory named path, along with any necessary parents.

func MkdirP

func MkdirP(path string, perm os.FileMode) error

MkdirP creates a directory named path, along with any necessary parents. MkdirP is equivalent to MkdirAll.

func ModTime

func ModTime(filename string) (time.Time, error)

ModTime return the Last Modified Time of the given filename.

func ModTimeUnix

func ModTimeUnix(filename string) (int64, error)

ModTimeUnix return the Last Modified Unix Timestamp of the given filename. Returns -1 if the file does not exist or if the file modtime cannot be determined.

func ModTimeUnixNano

func ModTimeUnixNano(filename string) (int64, error)

ModTimeUnixNano return the Last Modified Unix Time of nanoseconds of the given filename. Returns -1 if the file does not exist or if the file modtime cannot be determined.

func Mode

func Mode(filename string) (os.FileMode, error)

Mode return the FileMode of the given filename. Returns 0 if the file does not exist or if the file mode cannot be determined.

func Perm

func Perm(filename string) (os.FileMode, error)

Perm return the Unix permission bits of the given filename. Returns 0 if the file does not exist or if the file mode cannot be determined.

func PutContents

func PutContents(filename, content string) error

PutContents writes the contents of the string to filename. PutContents is equivalent to WriteString.

func RandString

func RandString(len int) string

func Read

func Read(filename string) ([]byte, error)

Read reads the file named by filename and returns the contents.

func ReadString

func ReadString(filename string) (string, error)

ReadString reads the file named by filename and returns the contents as string.

func Remove

func Remove(name string) error

Remove removes the named file or directory.

func RemoveAll

func RemoveAll(path string) error

RemoveAll removes path and any children it contains.

func Rename

func Rename(oldpath, newpath string) error

Rename renames (moves) a file

func Rmdir

func Rmdir(path string) error

Rmdir removes path and any children it contains. Rmdir is equivalent to RemoveAll.

func Sha1

func Sha1(filename string) (string, error)

Sha1 returns a SHA1 hash of file

func Size

func Size(filename string) (int64, error)

Size return the size of the given filename. Returns -1 if the file does not exist or if the file size cannot be determined.

func String

func String(s string) *string

func TempFile

func TempFile() (*os.File, error)

TempFile creates a new temporary file in the default directory for temporary files (see os.TempDir), opens the file for reading and writing, and returns the resulting *os.File.

func TempName

func TempName() (string, error)

TempName creates a new temporary file in the default directory for temporary files (see os.TempDir), opens the file for reading and writing, and returns the filename.

func Touch

func Touch(filename string) error
func Unlink(name string) error

Unlink removes the named file or directory. Unlink is equivalent to Remove.

func Write

func Write(filename string, content []byte) error

Write writes data to a file named by filename.

func WriteString

func WriteString(filename, content string) error

WriteString writes the contents of the string to filename.

Types

type FileInfo

type FileInfo os.FileInfo

func GetFileInfo

func GetFileInfo(name string) (FileInfo, error)

GetFileInfo returns a FileInfo describing the named file

type FilesInfo

type FilesInfo []FileInfo

func Find

func Find(pattern string) (FilesInfo, error)

Find returns the FilesInfo([]FileInfo) of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

func (FilesInfo) Len

func (f FilesInfo) Len() int

func (FilesInfo) SortByModTime

func (fis FilesInfo) SortByModTime()

SortByModTime sorts a slice of files by file modified time in increasing order.

func (FilesInfo) SortByModTimeReverse

func (fis FilesInfo) SortByModTimeReverse()

SortByModTimeReverse sorts a slice of files by file modified time in decreasing order.

func (FilesInfo) SortByName

func (fis FilesInfo) SortByName()

SortByName sorts a slice of files by filename in increasing order.

func (FilesInfo) SortByNameReverse

func (fis FilesInfo) SortByNameReverse()

SortByNameReverse sorts a slice of files by filename in decreasing order.

func (FilesInfo) SortBySize

func (fis FilesInfo) SortBySize()

SortBySize sorts a slice of files by filesize in increasing order.

func (FilesInfo) SortBySizeReverse

func (fis FilesInfo) SortBySizeReverse()

SortBySizeReverse sorts a slice of files by filesize in decreasing order.

func (FilesInfo) Swap

func (f FilesInfo) Swap(i, j int)

Directories

Path Synopsis
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client
Package gorequest inspired by Nodejs SuperAgent provides easy-way to write http client

Jump to

Keyboard shortcuts

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