Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadFile ¶
DownloadFile downloads a file from the provided URL and saves it to the specified location on the local filesystem. The function takes the source URL and the destination path as inputs and returns the path where the file was saved or an error.
Parameters:
url: A string representing the URL of the file to be downloaded. dest: A string representing the destination path where the file should be saved on the local filesystem.
Returns:
string: The path where the downloaded file was saved. error: An error if the function fails to download the file.
Example ¶
package main import ( "log" netutils "github.com/l50/goutils/v2/net" ) func main() { url := "http://example.com/path/to/file" dest := "/path/to/save/location" file, err := netutils.DownloadFile(url, dest) if err != nil { log.Fatalf("failed to download file: %v", err) } _ = file }
Output:
func PublicIP ¶
PublicIP uses several external services to get the public IP address of the system running it, using github.com/GlenDC/go-external-ip. The function takes an IP protocol version (4 or 6) as input and returns the public IP address as a string or an error.
Parameters:
protocol: A uint representing the IP protocol version (4 or 6).
Returns:
string: The public IP address of the system in string format. error: An error if the function fails to retrieve the public IP address.
Example ¶
package main import ( "log" "net" netutils "github.com/l50/goutils/v2/net" ) func main() { protocol := uint(4) // or 6 for IPv6 ip, err := netutils.PublicIP(protocol) if err != nil { log.Fatalf("failed to get public IP address: %v", err) } if net.ParseIP(ip) == nil { log.Fatal("invalid IP address received") } _ = ip }
Output:
Types ¶
This section is empty.