Documentation
¶
Index ¶
- Constants
- func AbsInt(value int) int
- func AbsInt64(value int64) int64
- func AnyToBool(v any) bool
- func AnyToInt64Ok(v any) (int64, bool)
- func AnyToInt64OrZero(v any) int64
- func AnyToString(v any) string
- func AnyToStringOk(v any) (s string, b bool)
- func AskUserChoiceMultiple(prompt string, options_list []string, unique bool) (choice_list []int, err error)
- func AskUserChoiceSingle(prompt string, options_list []string) (choice int, err error)
- func AssertEmpty(v any, message ...string)
- func AssertEqual[T comparable](a T, b T, message ...string)
- func AssertNil(v any, message ...string)
- func AssertNotEmpty(v any, message ...string)
- func AssertNotNil(v any, message ...string)
- func CallerSignature(skip int) string
- func CountValues(value interface{}, values_list ...interface{}) (count int)
- func ExecCmd(cmd_path string, args []string) (string, error)
- func ExecCmdPrint(cmd_path string, args []string) error
- func ExecCmdWaitAndPrint(cmd_path string, args []string) (output string, err error)
- func ExecCommandLine(command_line string) (string, error)
- func FileSha256(path string) (string, error)
- func FormatFileSize(size int64) string
- func GetDirAbsolutePath(path string) (abs_path string, err error)
- func HideConsole()
- func InSlice[E comparable, S ~[]E](needle E, slice S) bool
- func Int64Sign(value int64) int64
- func IntSign(value int) int
- func IsDirEmpty(path string) (bool, error)
- func IsDirExists(path string) bool
- func IsEmpty(v any) bool
- func IsFileExists(path string) bool
- func IsLinux() bool
- func IsStructEmbeds(s interface{}, embedded_type reflect.Type) bool
- func IsStructTypeEmbeds(s_type reflect.Type, embedded_type reflect.Type) bool
- func IsSystemdAvailable() bool
- func IsWindows() bool
- func LoadYamlSettingFromFile(path string, settings interface{}) error
- func PanicWithSignature(message any) string
- func PanicWithSignatureF(message string, args ...any) string
- func PrintYamlSettings(settings interface{})
- func Ptr[T any](v T) *T
- func RandomLetter(upperOnly bool) string
- func RandomString(length int) string
- func RandomWord(minLength, maxLength int, capitalize bool) string
- func RandomWords(count, minLength, maxLength int, capitalize bool) string
- func SaveYamlSettingToFile(path string, comment string, settings interface{}) error
- func SimpleGet(url string) (string, error)
- func SliceWalk[S ~[]E, E any](originalSlice S, fn func(E) E) S
- func SlicesIntersection[S ~[]E, E comparable](slice_a S, slice_b S) S
- func SplitArgumentsString(str string) []string
- func UniqueSlice[S ~[]E, E any](slice S) S
- type Lockable
- type LockableI
- type ServiceData
- type Values
Constants ¶
const SystemdServiceDirPath = "/etc/systemd/system"
Variables ¶
This section is empty.
Functions ¶
func AnyToInt64Ok ¶
Convert any value to Int64. Ok = true if it was converted
func AnyToInt64OrZero ¶
Try best to convert any value to int64. Returns 0 if value can not be converted.
func AnyToString ¶
Try best to convert any value to string, even if it is not a string at all.
func AnyToStringOk ¶
Convert any value to string. Ok = true if it is a string or Stringer, false if not. https://stackoverflow.com/questions/72267243/unioning-an-interface-with-a-type-in-golang
func AskUserChoiceMultiple ¶ added in v1.0.7
func AskUserChoiceMultiple(prompt string, options_list []string, unique bool) (choice_list []int, err error)
Prints options list and asks user for choice in console. Multiple options can be chosen. Input of single "0" (zero) means "Cancel" and [-1] slice returned
func AskUserChoiceSingle ¶ added in v1.0.7
Prints options list and asks user for choice in console. First chosen option is returned. -1 returned if nothing was selected or error occurred.
func AssertEmpty ¶
func AssertEqual ¶
func AssertEqual[T comparable](a T, b T, message ...string)
func AssertNotEmpty ¶
func AssertNotNil ¶
func CallerSignature ¶ added in v1.0.2
func CountValues ¶
func CountValues(value interface{}, values_list ...interface{}) (count int)
Returns number of `value` values found in `values_list`
func ExecCmdPrint ¶
Executes cmd and prints its output
func ExecCmdWaitAndPrint ¶
Executes cmd printing its stdout+stderr to current stdout during execution and returns its output after
func ExecCommandLine ¶
Executes whole string in command-line shell. Returns its output and/or error.
func FileSha256 ¶
func FormatFileSize ¶
Convert fille size to human-readable string
func GetDirAbsolutePath ¶
Returns absolute path for directory. If `path` is "" current working directory is used. Checks if directory exists.
func HideConsole ¶
func HideConsole()
Hides console (only under Windows)
Thanks to SyncThing! https://github.com/syncthing/syncthing/blob/main/lib/osutil/hidden_windows.go
func InSlice ¶ added in v1.0.5
func InSlice[E comparable, S ~[]E](needle E, slice S) bool
Returns true if needle is in slice (like PHP's in_array() function).
func IsDirEmpty ¶ added in v1.0.6
Returns true if directory is empty. Directory should exist and be accessible (permissions).
func IsDirExists ¶
Returns true if directory exists and access is not denied.
func IsEmpty ¶
Returns true if v value considered as empty (nil, "", 0 for int, 0.0 for float, false for bool).
func IsFileExists ¶
Returns true if file exists and access is not denied.
func IsStructEmbeds ¶
Checks if s - variable of struct type and it embeds embedded_type
func IsStructTypeEmbeds ¶
Checks if s_type - is a struct (or pointer to it) and it embeds embedded_type
func IsSystemdAvailable ¶
func IsSystemdAvailable() bool
func LoadYamlSettingFromFile ¶
func PanicWithSignature ¶ added in v1.0.2
func PanicWithSignatureF ¶ added in v1.0.3
func PrintYamlSettings ¶
func PrintYamlSettings(settings interface{})
func Ptr ¶
func Ptr[T any](v T) *T
One-liner to get pointer to function returned value. Example: pointer_t := mttools.Ptr(time.Now()) // you can not do pointer_t := &time.Now()
func RandomLetter ¶
Returns random letter. NOT cryptographically strong!
func RandomString ¶
Returns random string of given length. NOT cryptographically strong! https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
func RandomWord ¶
Generate random word
func RandomWords ¶
Generate sentence of random words
func SaveYamlSettingToFile ¶
func SliceWalk ¶ added in v1.0.2
func SliceWalk[S ~[]E, E any](originalSlice S, fn func(E) E) S
Returns new slice of same size and type, each element is result of calling fn() function.
func SlicesIntersection ¶
func SlicesIntersection[S ~[]E, E comparable](slice_a S, slice_b S) S
Returns slice of values found in both slice_a and slice_b
func SplitArgumentsString ¶
Splits string into array of strings. Each argument in string is single word or number, or string in double quotes.
func UniqueSlice ¶
func UniqueSlice[S ~[]E, E any](slice S) S
Returns slice of same type with just unique elements left in it
Types ¶
type ServiceData ¶
type ServiceData struct {
Name string //service name
User string //user
Group string //group
Executable string //path to executable file
WorkingDir string //full working directory path
Autostart bool //start service automatically
}
func (*ServiceData) InstallSystemdService ¶
func (unit *ServiceData) InstallSystemdService() error
func (*ServiceData) UninstallSystemdService ¶
func (unit *ServiceData) UninstallSystemdService() error
type Values ¶
type Values struct {
// contains filtered or unexported fields
}
func (*Values) Get ¶
Gets value by key, returns nil if there is no such key. Use GetOk() if you need distinguish nil values from key absence.