utils

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFile

func CreateFile(filepath string) error

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 CurlThis

func CurlThis(webpage string) (body []byte, err error)

func FileExists

func FileExists(path string) bool

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

func FolderExists(path string) bool

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 IsOnline

func IsOnline(url url.URL) error

IsOnline checks the provided URL for connectivity

Example
google, _ := url.Parse("https://google.com")
err := IsOnline(*google)

if err != nil {
	fmt.Println("Host is not accessible")
} else {
	fmt.Println("Host is accessible")
}
Output:

Host is accessible

func IsValidUrl

func IsValidUrl(toTest string) bool

IsValidUrl tests a string to determine if it is a well-structured url or not.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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