utils

package
v0.0.0-...-d66ac79 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI - converts bytes to {bytes, KB, MB, GB}

@param {int64} b - the number of bytes
@return {string} - the converted bytes

func Dedent

func Dedent(s string) string

Dedent - trims spaces on the left side of a line

@param {string} s - string to dedent
@return {string}

func Exists

func Exists(path string) (bool, error)

Exists - checks if a directory exists

@param {string} path - the path to the directory
@return {bool} - true if the directory exists
@return {error} - error

func FileSize

func FileSize(filename string) int64

FileSize - gets the file size

@param {string} filename - the filename
@return {int64} - the file size

func FileSizeToString

func FileSizeToString(filename string) string

FileSizeToString - gets the file size and converts it to {bytes, KB, MB, GB}

@param {string} filename - the filename
@return {string} - the file size

func GenerateRandomKey

func GenerateRandomKey(n int) string

GenerateRandomKey - generates a random key for the hill cipher

@param n - the size of the key
@return key - the key

func GetFileExtension

func GetFileExtension(filename string) string

GetFileExtension - gets the file extension

@param {string} filename - the filename
@return {string} - the file extension

func Indent

func Indent(s string, indent int) string

Indent - indents the string

@param s - the string to indent
@param indent - the number of spaces to indent
@return string - the indented string

func IsDirectory

func IsDirectory(path string) (bool, error)

IsDirectory returns true if the path is a directory.

@param path - the path to the file/directory.
@return bool - true if the path is a directory.

func IsEmpty

func IsEmpty(path string) bool

IsEmpty returns true if the directory is empty

@param path - the path to the directory
@return bool - true if the directory is empty

func IsHidden

func IsHidden(path string, forceHidden bool) bool

IsHidden returns true if the file/directory is hidden

@param path - the path to the file/directory
@param forceHidden - true if the file/directory is forced to be hidden
@return bool - true if the file/directory is hidden

func LPad

func LPad(s string, padding int) string

LPad - adds padding to the left of a command

@param {string} s - string to be worked on
@param {int} padding - number of padding
@return string

func MergeStructs

func MergeStructs(structs ...interface{}) reflect.Type

MergeStructs - merge multiple structs into one struct

@param {interface{}} structs - structs to be merged
@return interface{}

func Prompt

func Prompt(prompt *InteractivePrompt) bool

Prompt - prompt the user for confirmation.

@param {string} prompt - the prompt to display to the user.
@param {string} color - the color of the prompt.
@param {string} confirmation - the confirmation string.
@return {bool} - true if the user confirmed the prompt.

func RPad

func RPad(s string, padding int) string

RPad - adds padding to the right of a command

@param {string} s - string to be worked on
@param {int} padding - number of padding
@return string

Types

type Directory

type Directory struct {
	Name        string       `json:"name"`
	Path        string       `json:"path"`
	IsEmpty     bool         `json:"is_empty"`
	Files       []*File      `json:"files"`
	Directories []*Directory `json:"directories"`
}

Directory - a directory structure

func WalkDirectory

func WalkDirectory(root string) (*Directory, error)

WalkDirectory - repeatedly steps through a directory and returns the

@param {string} root - the path to the directory
@return {*Directory} - the directory info
@return {error} - error

type File

type File struct {
	Name string      `json:"name"`
	Path string      `json:"path"`
	Info fs.FileInfo `json:"info"`
}

File - a file structure

func GetFile

func GetFile(path string) *File

GetFile - gets the file

@param {string} path - the path to the file
@return {File} - the file

func GetFiles

func GetFiles(path string) []*File

GetFiles - gets the files in a directory

@param {string} path - the path to the directory
@return {[]File} - the files

type InteractivePrompt

type InteractivePrompt struct {
	Prompt       string
	Type         string // warning, error, info, success, danger, default
	Confirmation bool
}

InteractivePrompt - the prompt to display to the user.

Jump to

Keyboard shortcuts

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