utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MINUTE = 60
	HOUR   = MINUTE * 60
	DAY    = HOUR * 24
	MONTH  = DAY * 30
	YEAR   = MONTH * 12
	BYTE   = 1
	KB     = 1024 * BYTE
	MB     = 1024 * KB
	GB     = 1024 * MB
)

Variables

This section is empty.

Functions

func DeleteFile

func DeleteFile(filepath string) error

DeleteFile will delete filepath permanently. Returns an error in case there's any.

func FormatMemory

func FormatMemory(input int) string

FormatMemory will format memory val

func FormatUptime

func FormatUptime(startTime, currentTime int64) string

FormatUptime will figure out current proc uptime

func GetFile

func GetFile(filepath string) (*os.File, error)

GetFile will open filepath. Returns a tuple with a file and an error in case there's any.

func GetTableWriter added in v0.2.1

func GetTableWriter() *tablewriter.Table

GetTableWriter will return instance of tablewriter

func PadString

func PadString(str string, totalSize int) string

PadString will add totalSize spaces evenly to the right and left side of str. Returns str after applying the pad.

func SafeReadTomlFile

func SafeReadTomlFile(filename string, v interface{}) error

SafeReadTomlFile will try to acquire a lock on the file and then read its content afterwards. Returns an error in case there's any.

func SafeWriteTomlFile

func SafeWriteTomlFile(v interface{}, filename string) error

SafeWriteTomlFile will try to acquire a lock on the file and then write to it. Returns an error in case there's any.

func WriteFile

func WriteFile(filepath string, b []byte) error

WriteFile will write the info on array of bytes b to filepath. It will set the file permission mode to 0660 Returns an error in case there's any.

Types

type FileMutex

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

FileMutex is a wrapper used to create lock on files.

func MakeFileMutex

func MakeFileMutex(filename string) *FileMutex

MakeFileMutex will create a FileMutex intance. Returns a FileMutex instance.

func (*FileMutex) Lock

func (fMutex *FileMutex) Lock()

Lock will try to acquire a lock on the file.

func (*FileMutex) Unlock

func (fMutex *FileMutex) Unlock()

Unlock will try to release a lock on a file.

Jump to

Keyboard shortcuts

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