net

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 3 Imported by: 0

README

goutils/net

The net package is a part of goutils library. It provides utility functions for network related operations in Go.


Functions

DownloadFile
func DownloadFile(url string, dest string) (string, error)

Downloads a file from the provided URL and saves it to the specified location on the local filesystem.

PublicIP
func PublicIP(protocol uint) (string, error)

Obtains the public IP address of the system. This function uses multiple external services to determine the IP address, taking as input an integer representing the IP protocol version (4 or 6), and returns the public IP address as a string. If the retrieval fails, an error is returned.


Installation

To use the goutils/net package, you need to install it via go get:

go get github.com/l50/goutils/str

Usage

After installation, you can import it in your project:

import "github.com/l50/goutils/net"

Tests

To run the tests for the goutils/net package, navigate to your $GOPATH/src/github.com/l50/goutils/net directory and run go test:

go test -v

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(url string, dest string) (string, error)

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:

url := "http://example.com/path/to/file" dest := "/path/to/save/location" file, err := DownloadFile(url, dest)

if err != nil {
  log.Fatalf("failed to download file: %v", err)
}

log.Printf("File downloaded to: %s\n", file)

func PublicIP

func PublicIP(protocol uint) (string, error)

PublicIP uses several external services to get the public IP address of the system running it, using the package 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:

protocol := uint(4) // or 6 for IPv6 ip, err := PublicIP(protocol)

if err != nil {
  log.Fatalf("failed to get public IP address: %v", err)
}

log.Printf("Public IP address: %s\n", ip)

Types

This section is empty.

Jump to

Keyboard shortcuts

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