goof

package module
v0.0.0-...-464a0fa Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: LGPL-3.0 Imports: 24 Imported by: 98

README

Build Status GoDoc

goof

Good Functions for go

Documentation

Overview

A collection of functions I use very often

This is a convenient place to store all the functions that I use in a lot of programs. They were useful for me, so they might be useful for you too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsFloat32

func AbsFloat32(x float32) float32

func AbsFloat64

func AbsFloat64(x float64) float64

func AbsInt

func AbsInt(x int) int

func AllIps

func AllIps() []string

func AppendStringToFile

func AppendStringToFile(path, text string) error

Write text at the end of a file. Note that the file is opened and closed on each call, so it's not a good choice for logging..

func Atoi

func Atoi(s string) int

String to int, single return value

func CatFile

func CatFile(path string) []byte

Return contents of file. It's just ioutil.ReadFile, but with only one return value, and instead it will panic on any error

func Chomp

func Chomp(s string) string

Delete a trailing /n, if it exists

func Clamp

func Clamp(a, min, max int) int

func Command

func Command(cmd string, args []string) string

Run a command. The first arg is the path to the executable, the rest are program args. Returns stdout and stderr mixed together

func ConfBool

func ConfBool(f map[string]interface{}, key string, default_value bool) bool

Find a bool value in the config and return it

func ConfFloat64

func ConfFloat64(f map[string]interface{}, key string, default_value float64) float64

Find a Float64 value in the config and return it

func ConfInt

func ConfInt(f map[string]interface{}, key string, default_value int) int

Find an int value in the config and return it

func ConfString

func ConfString(f map[string]interface{}, key string, default_value string) string

Find a string value in the config and return it

func ConfigFilePath

func ConfigFilePath(filename string) string

Build a path to a config file, from the default config location

func Cwd

func Cwd() string

Current working directory

func ExecutablePath

func ExecutablePath() string

Returns the directory this executable is in

func Exists

func Exists(path string) bool

Does this file or directory exist?

func ExternalIP

func ExternalIP() (string, error)

Try to find the network interface that is connected to the internet, and get its IP address This does not find the IP of your firewall or WAN connection, just the IP on the network that you are directly connected to

func FileContains

func FileContains(filename string, search string) bool

Open a file, search it for the given string

func GetOutboundIP

func GetOutboundIP() (localAddr net.IP)

Attempt to get the primary network address

func Grep

func Grep(search, str string) string

Searches a string to see if any lines in it match search

func Hash_file_md5

func Hash_file_md5(filePath string) (string, error)

Calculate the MD5sum of a file

func HomeDirectory

func HomeDirectory() string

Cross platform find home (user) directory

func HomePath

func HomePath(p string) string

Cross platform make path from home directory

func IsDir

func IsDir(path string) bool

Is this path a directory? Any error results in false

func IsDirr

func IsDirr(pth string) (bool, error)

Is this path a directory? Return error if error occurs (e.g. does not exist)

func ListGrep

func ListGrep(search string, strs []string) []string

Searches a list of strings, return any that match search. Case insensitive

func ListGrepInv

func ListGrepInv(search string, strs []string) []string

Searches a list of strings, return any that don't match search. Case insensitive

func Ls

func Ls(dir string) []string

List all files in a directory

func LslR

func LslR(dir string) []string

List all files in a directory, and recursively in its subdirectories

func Make_agent_plist

func Make_agent_plist(appName, appPath string) string

func Odd

func Odd(x int) bool

Return true if x is odd

func OpenBufferedInput

func OpenBufferedInput(filename string, compression string) *bufio.Reader

func OpenFirewall

func OpenFirewall(programPath, programName string)

Register programPath with Windows UAC so it can listen on network ports. programName is a descriptive name

func OpenInput

func OpenInput(filename string, compression string) io.Reader

Opens a file or stdin (if filename is ""). Can open compressed files, and can decompress stdin. Compression is "bz2" or "gz". Pass "" as a filename to read stdin.

func Panicf

func Panicf(format string, a ...interface{})

Use printf arguments to panic with a message

func QC

func QC(strs []string) (string, error)

Run a command. The first element is the path to the executable, the rest are program arguments. Returns stdout

func QCI

func QCI(strs []string) error

Run a command in an interactive shell. If there isn't a terminal associated with this program, one should be opened for you. The first element is the path to the executable, the rest are program arguments. Returns stdout

func QuickCommand

func QuickCommand(cmd *exec.Cmd) (string, error)

Run a command, wait for it to finish and then return stdout

func QuickCommandInteractive

func QuickCommandInteractive(cmd *exec.Cmd) error

Run a command in an interactive shell. If there isn't a terminal associated with this program, one should be opened for you.

The current STDIN/OUT/ERR will be provided to the child process

func QuickCommandInteractivePrep

func QuickCommandInteractivePrep(strs []string) *exec.Cmd

Run a command in an interactive shell. If there isn't a terminal associated with this program, one should be opened for you.

The current STDIN/OUT/ERR will be provided to the child process

func ReadOrMakeConfig

func ReadOrMakeConfig(filename string, default_config string) map[string]interface{}

Attempt to read config from filename. If filename does not exist, write default_config to the file and parse that data.

func Restart

func Restart()

Restart the current application Attemtps to read the command line parameters from the current process

func ScanHosts

func ScanHosts(timeout, port int, outch chan string)

Attempt to connect to PORT on every IP address in your class C network

func ScanHostsRec

func ScanHostsRec(timeout, port, elapsed int, outch chan string)

Attempt to connect to PORT on every IP address in your class C network

func Seq

func Seq(min, max int) []int

Return an array of integers from min to max, so you can range over them

func Sequence

func Sequence(start, end int) []int

func Shell

func Shell(cmd string) string

Run cmd as a shell command, return the output

func ShortenString

func ShortenString(length int, s string) string

If string is longer than length, return the first length characters, otherwise return the string

func ShortenStringWithEllipsis

func ShortenStringWithEllipsis(length int, s string) string

If string is longer than length, return the first length-3 characters and ..., otherwise return the string

func SimpleGet

func SimpleGet(path string) ([]byte, error)

func SplitPath

func SplitPath(path string) []string

func ToChar

func ToChar(i int) rune

ASCII id -> char

func ToCharStr

func ToCharStr(i int) string

ASCII id -> string

func WrapCmd

func WrapCmd(cmd *exec.Cmd, channel_length int) (chan []byte, chan []byte, chan []byte)

Starts a program, in the background, and returns three Go pipes of type (chan []byte), which are connected to the process's STDIN, STDOUT and STDERR. Bytes will be read from the wrapped program and written to the channels as quickly as possible, but there are no guarantees on speed or how many bytes are delivered per message in the channel. This routine does no buffering, however the wrapped process can use buffers, so you still might not get prompt delivery of your data. In general, most programs will use line buffering unless you can force them not to.

Channel length is the buffer length of the go pipes

func WrapHandle

func WrapHandle(fileHandle uintptr, channel_length int) (chan []byte, chan []byte)

Takes a (c-style) filehandle, and returns go queues that let you write to and read from that handle Bytes will be read from the wrapped handle and written to the channels as quickly as possible, but there are no guarantees on speed or how many bytes are delivered per message in the channel. This routine does no buffering, however the wrapped process can use buffers, so you still might not get prompt delivery of your data. In general, most programs will use line buffering unless you can force them not to.

Channel length is the buffer length of the go pipes

func WrapProc

func WrapProc(pathToProgram string, channel_length int) (chan []byte, chan []byte, chan []byte)

Starts a program, in the background, and returns three Go pipes of type (chan []byte), which are connected to the process's STDIN, STDOUT and STDERR. Bytes will be read from the wrapped program and written to the channels as quickly as possible, but there are no guarantees on speed or how many bytes are delivered per message in the channel. This routine does no buffering, however the wrapped process can use buffers, so you still might not get prompt delivery of your data. In general, most programs will use line buffering unless you can force them not to.

Channel length is the buffer length of the go pipes

func WrappedTraceroute

func WrappedTraceroute(target string) []string

func WriteMacAgentStart

func WriteMacAgentStart(appName string)

Types

This section is empty.

Directories

Path Synopsis
demo.go
demo.go

Jump to

Keyboard shortcuts

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