gotools

package module
v0.0.0-...-5a50be7 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 11 Imported by: 1

README

Go-tools

The functions found here are tools that I find useful for everyday development.

Installation

Simply run go get github.com/CrestFallenTurtle/Go-tools to add it to your project

Contents

The following table contains all tools available in this project.

Function Description Note
Contains Checks if the the supplied string contains a substring Returns a map[string]bool
EraseDelimiter Erases any delimiter from your string
GenerateRandomBool Generates and returns true or false
GenerateRandomIntBetween Generates a random int in an interval
GenerateRandomInt Generates a random int between 1 and 128
GrabCWD Returns the current working directory Exits on error
GrabExecutableName Returns the executables name
GrabExecutablePath Returns the path where the executable is housed
GrabHomeDir Returns the current users home directory Exits on error
GrabUsername Returns the current users username Exits on error
ReverseString Reverses a string
SplitString Splits a string and returns a rune array
StartsWith Checks if a string starts with a substring
EndsWith Checks if a string ends with a substring
StringToBoolean Converts a string to a boolean Requires that the string is "true" or "false"
StringToInt Converts a string to a int Returns -1 when it fails to convert
IntToString Converts a int to a string

Examples

Check out the files under test/ to see how each function can be utilized

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(target string, selection []string) map[string]bool

Wrapper for the strings.Contains function, but takes in a array contaning strings to look for and returns a map in the format of { "<key>":"<true/false>" }

func EndsWith

func EndsWith(target string, selection []string) map[string]bool

Wrapper for the strings.HasSuffix function, but takes in a array contaning strings to look for and returns a map in the format of { "<key>":"<true/false>" }

func EraseDelimiter

func EraseDelimiter(line string, delimiters []string, count int) string

Erases all occurences of the delimiter in the string

func GenerateRandomBool

func GenerateRandomBool() bool

Generates a random bool

func GenerateRandomInt

func GenerateRandomInt() int

Generates a random number between 1 and 128

func GenerateRandomIntBetween

func GenerateRandomIntBetween(min int, max int) int

Generates a random number between min and max

func Generate_random_n_string

func Generate_random_n_string(size int) string

Generates a random string based on the length of the input

func Generate_random_string

func Generate_random_string() string

Generates a random string between the lengthes of 1 and 128

func GrabCWD

func GrabCWD() string

Grabs the current working path

func GrabExecutableName

func GrabExecutableName() string

Returns the executable name

func GrabExecutablePath

func GrabExecutablePath() string

Returns the path to the executable file including the executable file name

func GrabHomeDir

func GrabHomeDir() string

Grabs the current users home directory

func GrabUsername

func GrabUsername() string

Returns the username of the current user

func IntToString

func IntToString(value int) string

Converts the provided int to a string

func ReverseString

func ReverseString(target *string)

Takes the string to work in as a pointer, and makes it go from abc to cba

func SplitString

func SplitString(target string) []string

Splits a string into a string array and returns it

func StartsWith

func StartsWith(target string, selection []string) map[string]bool

Wrapper for the strings.HasPrefix function, but takes in a array contaning strings to look for and returns a map in the format of { "<key>":"<true/false>" }

func StringToBoolean

func StringToBoolean(value string) bool

Converts the provided string to into a boolean

func StringToInt

func StringToInt(value string) int

Tries to convert the provided string to an int, and returns either the converted value or -1 if it failed

Types

This section is empty.

Jump to

Keyboard shortcuts

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