tools

package
v0.0.0-...-6ebe776 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDataToFile

func AddDataToFile(srcfile, dstfile string, data []byte) error

*

  • Add data to file
  • @remarks Added data is optional
  • @param srcFile Source file
  • @param dstFile Destination file
  • @param data Data to add at the end of destination file
  • @returns Nothing or an error

func CopyFile

func CopyFile(srcFile, dstFile string) error

*

  • Copy file
  • @remarks This function simply copies a file to another
  • @param srcFile Source file
  • @param dstFile Destination file
  • @returns Nothing or an error

NOTE: CopyFile does not have unit test as it uses AddDataToFile which is already tested

func CreateTemp

func CreateTemp(baseName string) (string, error)

*

  • Create a temporary file
  • @remarks Create temporary file with a name based on baseName
  • @param baseName String to trim
  • @returns Created filename or an error

func GetFileFromURL

func GetFileFromURL(url string, fileName string, skipVerify bool) error

*

  • Get File through HTTP
  • @param url URL where to download the file
  • @param fileName of the file to create
  • @param skipVerify Skip TLS check if needed
  • @returns Nothing or an error

func GetFilesList

func GetFilesList(dir string, pattern string) ([]string, error)

*

  • Get a list of files
  • @param dir Directory where to search
  • @param pattern Search pattern
  • @returns List of files or an error

func HTTPShare

func HTTPShare(directory, listenAddr string)

*

  • Share files through HTTP (simple way, no security at all!)
  • @remarks A HTTP server is up and running
  • @param directory The directory where is files are
  • @param listenAddr Port where to listen to
  • @returns Nothing

TODO: Use Server function from http helpers instead

func IsIPv4

func IsIPv4(value string) bool

*

  • Check if the string is a valid IPv4
  • @param value Value to check
  • @returns True if value is an IPv4, otherwise False

func Sed

func Sed(oldValue, newValue, file string) error

*

  • Simple sed command
  • @param oldValue Value or simple regex to modify
  • @param newValue New value to set
  • @param file File to modify
  • @returns Nothing or an error

Sed code partially from https://forum.golangbridge.org/t/using-sed-in-golang/23526/16

func SetTimeout

func SetTimeout(timeout time.Duration) time.Duration

*

  • Configure a timeout based on TIMEOUT_SCALE env variable
  • @remarks Multiply a duration with TIMEOUT_SCALE value
  • @param timeout Initial timeout value
  • @returns Modified timeout value

func TrimStringFromChar

func TrimStringFromChar(s, c string) string

*

  • Trim a string
  • @remarks Remove all from s string after c char
  • @param s String to trim
  • @param c Character used as a separator
  • @returns Trimmed string

func WriteFile

func WriteFile(dstfile string, data []byte) error

*

  • Write data to file
  • @remarks This function simply writes data to a file
  • @param dstFile Destination file
  • @param data Data to write
  • @returns Nothing or an error

Types

type Client

type Client struct {
	Host     string
	Username string
	Password string
}

func (*Client) GetFile

func (c *Client) GetFile(localFile, remoteFile string, perm fs.FileMode) error

*

  • Get file through SSH (a SCP in fact!)
  • @param localFile Local file to create
  • @param remoteFile Remote file to copy from
  • @param perm Permissions to set on the local file
  • @returns Nothing or an error

func (*Client) RunSSH

func (c *Client) RunSSH(cmd string) (string, error)

*

  • Run a command on client through SSH
  • @param Client is the receiver where to execute the command
  • @param cmd Command to execute
  • @returns Result of the command or an error

func (*Client) SendFile

func (c *Client) SendFile(src, dst, perm string) error

*

  • Send file through SSH (a SCP in fact!)
  • @param src Source file
  • @param dst Destination file on the client
  • @param perm Permissions to set on the file
  • @returns Nothing or an error

Jump to

Keyboard shortcuts

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