Documentation ¶
Index ¶
- func ArrayContains(haystack []string, needle string) (int, bool)
- func CreateFile(filepath string) error
- func FileExists(path string) bool
- func FolderExists(path string) bool
- func GetEnv(key string) (string, error)
- func IsOnline(url url.URL) error
- func ParseAndGetDocument(uri string) *goquery.Document
- func RemoveFile(path string) error
- func StringContains(baseString string, stringlist ...string) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayContains ¶
ArrayContains takes a slice of strings and looks for an element in it. If found it returns its index, otherwise it will return -1 and false.
Example ¶
haystack := []string{"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "India"} needle := "Golf" index, exists := ArrayContains(haystack, needle) if !exists { fmt.Printf("Element %s could not be found", needle) } else { fmt.Printf("Element %s was found with index %d", needle, index) }
Output: Element Golf was found with index 6
func CreateFile ¶
CreateFile creates a file on the given filepath along with any necessary parents, and returns nil, or else returns an error.
Example ¶
err := CreateFile(existingFile) if err != nil { fmt.Println("Failed to create file because it already exists") } else { fmt.Println("File has been created successfully!") }
Output: Failed to create file because it already exists
func FileExists ¶
FileExists reports whether the provided file exists.
Example ¶
exists := FileExists("/missing-file.txt") if exists { fmt.Println("File exists") } else { fmt.Println("File does not exist") }
Output: File does not exist
func FolderExists ¶
FolderExists reports whether the provided directory exists.
Example ¶
exists := FolderExists("/a-non-existing-folder") if exists { fmt.Println("Folder exists") } else { fmt.Println("Folder does not exist") }
Output: Folder does not exist
func GetEnv ¶
GetEnv returns the value of the environment variable specified by key, if the variable is set.
Example ¶
variable := "MY_VAR" os.Setenv(variable, "some-value") val, err := GetEnv(variable) if err == nil { fmt.Println(val) } else { fmt.Println(err) }
Output: some-value
func IsOnline ¶
IsOnline checks the provided URL for connectivity
Example ¶
google, _ := url.Parse("https://google.com") if err := IsOnline(*google); err != nil { fmt.Println("Host is not accessible") } else { fmt.Println("Host is accessible") }
Output: Host is accessible
func ParseAndGetDocument ¶
ParseAndGetDocument fetches the GoQuery document object for a given link
func RemoveFile ¶
RemoveFile deletes the specified file
Example ¶
_ = CreateFile(fileToDelete) err := RemoveFile(fileToDelete) if err == nil { fmt.Println("File deleted") } else { fmt.Println("Unable to delete file") }
Output: File deleted
func StringContains ¶
StringContains searches for a string in a series of strings
Example ¶
contains := StringContains("This is a string", "not", "are", "simple") if contains { fmt.Println("String contains at least one of the arguments") } else { fmt.Println("String does not contain any of the arguments") }
Output: String does not contain any of the arguments
Types ¶
This section is empty.