u

package
v0.0.0-...-a8fdd77 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: MIT, MIT Imports: 12 Imported by: 0

README

u

Random Go common utility functions that I use in multiple projects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(dst, src string) error

func CreateDirForFile

func CreateDirForFile(path string) error

func CreateDirForFileMust

func CreateDirForFileMust(path string) string

func CreateDirIfNotExists

func CreateDirIfNotExists(path string) error

func CreateDirIfNotExistsMust

func CreateDirIfNotExistsMust(dir string) string

func CreateDirMust

func CreateDirMust(path string)

func CreateZipWithDirContent

func CreateZipWithDirContent(zipFilePath, dirToZip string) error

the names of files inside the zip file are relatitve to dirToZip e.g. if dirToZip is foo and there is a file foo/bar.txt, the name in the zip will be bar.txt

func DirifyFileName

func DirifyFileName(fn string) string

func DurationToString

func DurationToString(d time.Duration) string

func ExpandTildeInPath

func ExpandTildeInPath(s string) string

func GetFileSize

func GetFileSize(path string) (int64, error)

func IsLinux

func IsLinux() bool

func IsMac

func IsMac() bool

func ListFilesInDir

func ListFilesInDir(dir string, recursive bool) []string

func PanicIf

func PanicIf(cond bool, args ...interface{})

func PanicIfErr

func PanicIfErr(err error)

func PathExists

func PathExists(path string) bool

treats any error (e.g. lack of access due to permissions) as non-existence

func PathIsDir

func PathIsDir(path string) (isDir bool, err error)

Returns true, nil if a path exists and is a directory Returns false, nil if a path exists and is not a directory (e.g. a file) Returns undefined, error if there was an error e.g. because a path doesn't exists

func ReadLinesFromFile

func ReadLinesFromFile(path string) ([]string, error)

func ReadLinesFromReader

func ReadLinesFromReader(r io.Reader) ([]string, error)

func Sha1HexOfBytes

func Sha1HexOfBytes(data []byte) string

func Sha1HexOfFile

func Sha1HexOfFile(path string) (string, error)

func Sha1OfBytes

func Sha1OfBytes(data []byte) []byte

func Sha1OfFile

func Sha1OfFile(path string) ([]byte, error)

func TimeSinceNowAsString

func TimeSinceNowAsString(t time.Time) string

func UserHomeDir

func UserHomeDir() string

func WriteBytesToFile

func WriteBytesToFile(d []byte, path string) error

Types

type Semaphore

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

based on http://golang.org/doc/effective_go.html#channels

func NewSemaphore

func NewSemaphore(max int) *Semaphore

func (*Semaphore) Enter

func (s *Semaphore) Enter()

func (*Semaphore) Leave

func (s *Semaphore) Leave()

Jump to

Keyboard shortcuts

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