utils

package
v0.0.0-...-130d745 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 8 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 CheckSourceFolderExit

func CheckSourceFolderExit(sourceFolder string) (bool, error)

CheckSourceFolderExit will check source code folder exist

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

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