util

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileMode is default file mode
	FileMode = 0644
	// DirFileMode is default directory file mode
	DirFileMode = 0755
)
View Source
const (
	// DefaultTerminalWidth is the terminal width when undefined
	DefaultTerminalWidth = 80
)

Variables

View Source
var GOOS = runtime.GOOS

GOOS is the OS name

Functions

func CopyFile

func CopyFile(source, dest string) error

CopyFile copies source file to destination, preserving mode: - source: the source file - dest: the destination file Return: error if something went wrong

func CopyFilesToDir

func CopyFilesToDir(dir string, files []string, toDir string, flatten bool) error

CopyFilesToDir copies files in root directory to destination directory: - dir: root directory - files: globs of source files - toDir: destination directory - flatten: tells if files should be flatten in destination directory Return: an error if something went wrong

func DirExists

func DirExists(dir string) bool

DirExists tells if directory exists: - dir: directory to test Return: a boolean that tells if directory exists

func ExpandUserHome

func ExpandUserHome(path string) string

ExpandUserHome expand path starting with "~/": - path: the path to expand Return: expanded path

func FileExists

func FileExists(file string) bool

FileExists tells if given file exists: - file: the name of the file to test Return: a boolean that tells if file exists

func FileIsExecutable

func FileIsExecutable(file string) bool

FileIsExecutable tells if given file is executable by user: - file: file to test Return: a boolean that tells if file is executable by user

func FindFiles

func FindFiles(dir string, includes, excludes []string, folder bool) ([]string, error)

FindFiles finds files in the context: - dir: the search root directory (current dir if empty) - includes: the list of globs to include - excludes: the list of globs to exclude - folder: tells if we should include folders Return the list of files as a slice of strings

func FindInPath

func FindInPath(executable string) []string

FindInPath search given executable in PATH: - executable: executable to search. Return: list of directories containing executable

func IsMap

func IsMap(object interface{}) bool

IsMap tells if given object is a map: - object: object to examine Return: a boolean that tells if object is a map

func IsSlice

func IsSlice(object interface{}) bool

IsSlice tells if given object is a slice: - object: object to examine Return: a boolean that tells if object is a slice

func ListContains

func ListContains(list []string, name string) bool

ListContains tells if a list contains given string

func MaxLineLength

func MaxLineLength(lines []string) int

MaxLineLength returns the maximum length of given lines: - lines: lines to examine Return: maximum length of lines as an integer

func MoveFilesToDir

func MoveFilesToDir(dir string, files []string, toDir string, flatten bool) error

MoveFilesToDir moves files in source directory to destination: - dir: root directory of source files - files: globs of files to move - toDir: destination directory - flatten: tells if files should be flatten in destination directory Return: an error if something went wrong

func PathToUnix

func PathToUnix(path string) string

PathToUnix turns a path to Unix format (with "/"): - path: path to turn to unix format Return: converted path

func PathToWindows

func PathToWindows(path string) string

PathToWindows turns a path to Windows format (with "\"): - path: path to turn to windows format Return: converted path

func ReadFile

func ReadFile(file string) ([]byte, error)

ReadFile reads given file and return it as a byte slice: - file: the file to read Return: - content as a slice of bytes - an error if something went wrong

func RemoveBlankLines

func RemoveBlankLines(text string) string

RemoveBlankLines removes blank lines of given string: - text: to text to process Return: a string without blank lines

func TerminalWidth

func TerminalWidth() int

TerminalWidth returns the terminal width

func ToMapStringInterface

func ToMapStringInterface(object interface{}) (map[string]interface{}, error)

ToMapStringInterface return interface as a map with string keys and interface values: - object: the maps of interfaces as an interface Return: - converted map of interfaces - an error if something went wrong

func ToMapStringString

func ToMapStringString(object interface{}) (map[string]string, error)

ToMapStringString return interface as a map with string keys and values: - object: the maps of strings as an interface Return: - converted map of strings - an error if something went wrong

func ToSliceString

func ToSliceString(object interface{}) ([]string, error)

ToSliceString return interface as a slice of strings: - object: the slice of strings or string as an interface Return: - converted slice of strings - an error if something went wrong

func ToString

func ToString(object interface{}) (string, error)

ToString returns a string from an interface: - object: the string as an interface Return: - converted string - an error if something went wrong

func Windows

func Windows() bool

Windows tells if we are running on windows Return: a boolean that tells if we are running on windows

Types

type Object

type Object map[string]interface{}

Object is a dictionary of interfaces

func NewObject

func NewObject(thing interface{}) (Object, error)

NewObject makes an object from an interface: - thing: the thing to convert to an object Return: - converted object - an error if something went wrong

func (Object) CheckFields

func (object Object) CheckFields(fields []string) error

CheckFields checks that object has no field whose name is not in given list: - fields: list of fields to check Return: an error if something went wrong

func (Object) Copy

func (object Object) Copy() Object

Copy returns a copy of the object

func (Object) Fields

func (object Object) Fields() []string

Fields return fields of the object as a list of strings

func (Object) GetBoolean

func (object Object) GetBoolean(field string) (bool, error)

GetBoolean returns an object field as a boolean: - field: name of the field to get Return: - boolean content of the field - an error if something went wrong

func (Object) GetInteger

func (object Object) GetInteger(field string) (int, error)

GetInteger returns an object field as a integer: - field: name of the field to get Return: - integer content of the field - an error if something went wrong

func (Object) GetList

func (object Object) GetList(field string) ([]interface{}, error)

GetList returns an object field as a slice of interfaces: - field: name of the field to get Return: - content of the field as a slice of interfaces - an error if something went wrong

func (Object) GetListStrings

func (object Object) GetListStrings(field string) ([]string, error)

GetListStrings returns an object field as a slice of strings: - field: name of the field to get Return: - content of the field as a slice of strings - an error if something went wrong

func (Object) GetListStringsOrString

func (object Object) GetListStringsOrString(field string) ([]string, error)

GetListStringsOrString returns an object field as a slice of strings: - field: name of the field to get Return: - content of the field as a slice of strings - an error if something went wrong

func (Object) GetMapStringString

func (object Object) GetMapStringString(field string) (map[string]string, error)

GetMapStringString returns an object field as a map with string keys and values: - field: name of the field to get Return: - content of the field map with string keys and values - an error if something went wrong

func (Object) GetObject

func (object Object) GetObject(field string) (Object, error)

GetObject returns an object field as an object: - field: name of the field to get Return: - content of the field as an object - an error if something went wrong

func (Object) GetString

func (object Object) GetString(field string) (string, error)

GetString returns an object field as a string: - field: name of the field to get Return: - string content of the field - an error if something went wrong

func (Object) HasField

func (object Object) HasField(field string) bool

HasField tells if object has given field: - field: name of the field to check Return: a boolean that tells if object has field

func (Object) ToMapStringString

func (object Object) ToMapStringString() (map[string]string, error)

ToMapStringString returns an object as a map with string keys and values. Return: - object as a map with string keys and values - an error if something went wrong

Jump to

Keyboard shortcuts

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