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 ¶
- func AbsFloat32(x float32) float32
- func AbsFloat64(x float64) float64
- func AbsInt(x int) int
- func AllIps() []string
- func AppendStringToFile(path, text string) error
- func Atoi(s string) int
- func CatFile(path string) []byte
- func Chomp(s string) string
- func Clamp(a, min, max int) int
- func Command(cmd string, args []string) string
- func ConfBool(f map[string]interface{}, key string, default_value bool) bool
- func ConfFloat64(f map[string]interface{}, key string, default_value float64) float64
- func ConfInt(f map[string]interface{}, key string, default_value int) int
- func ConfString(f map[string]interface{}, key string, default_value string) string
- func ConfigFilePath(filename string) string
- func Cwd() string
- func ExecutablePath() string
- func Exists(path string) bool
- func ExternalIP() (string, error)
- func FileContains(filename string, search string) bool
- func GetOutboundIP() (localAddr net.IP)
- func Grep(search, str string) string
- func Hash_file_md5(filePath string) (string, error)
- func HomeDirectory() string
- func HomePath(p string) string
- func IsDir(path string) bool
- func IsDirr(pth string) (bool, error)
- func ListGrep(search string, strs []string) []string
- func ListGrepInv(search string, strs []string) []string
- func Ls(dir string) []string
- func LslR(dir string) []string
- func Make_agent_plist(appName, appPath string) string
- func Odd(x int) bool
- func OpenBufferedInput(filename string, compression string) *bufio.Reader
- func OpenFirewall(programPath, programName string)
- func OpenInput(filename string, compression string) io.Reader
- func Panicf(format string, a ...interface{})
- func QC(strs []string) (string, error)
- func QCI(strs []string) error
- func QuickCommand(cmd *exec.Cmd) (string, error)
- func QuickCommandInteractive(cmd *exec.Cmd) error
- func QuickCommandInteractivePrep(strs []string) *exec.Cmd
- func ReadOrMakeConfig(filename string, default_config string) map[string]interface{}
- func Restart()
- func ScanHosts(timeout, port int, outch chan string)
- func ScanHostsRec(timeout, port, elapsed int, outch chan string)
- func Seq(min, max int) []int
- func Sequence(start, end int) []int
- func Shell(cmd string) string
- func ShortenString(length int, s string) string
- func ShortenStringWithEllipsis(length int, s string) string
- func SimpleGet(path string) ([]byte, error)
- func SplitPath(path string) []string
- func ToChar(i int) rune
- func ToCharStr(i int) string
- func WrapCmd(cmd *exec.Cmd, channel_length int) (chan []byte, chan []byte, chan []byte)
- func WrapHandle(fileHandle uintptr, channel_length int) (chan []byte, chan []byte)
- func WrapProc(pathToProgram string, channel_length int) (chan []byte, chan []byte, chan []byte)
- func WrappedTraceroute(target string) []string
- func WriteMacAgentStart(appName string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsFloat32 ¶
func AbsFloat64 ¶
func AppendStringToFile ¶
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 CatFile ¶
Return contents of file. It's just ioutil.ReadFile, but with only one return value, and instead it will panic on any error
func Command ¶
Run a command. The first arg is the path to the executable, the rest are program args. Returns stdout and stderr mixed together
func ConfFloat64 ¶
Find a Float64 value in the config and return it
func ConfString ¶
Find a string value in the config and return it
func ConfigFilePath ¶
Build a path to a config file, from the default config location
func ExternalIP ¶
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 ¶
Open a file, search it for the given string
func GetOutboundIP ¶
Attempt to get the primary network address
func Hash_file_md5 ¶
Calculate the MD5sum of a file
func ListGrepInv ¶
Searches a list of strings, return any that don't match search. Case insensitive
func Make_agent_plist ¶
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 ¶
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 ¶
Run a command. The first element is the path to the executable, the rest are program arguments. Returns stdout
func QCI ¶
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 ¶
Run a command, wait for it to finish and then return stdout
func QuickCommandInteractive ¶
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 ¶
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 ¶
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 ScanHostsRec ¶
Attempt to connect to PORT on every IP address in your class C network
func ShortenString ¶
If string is longer than length, return the first length characters, otherwise return the string
func ShortenStringWithEllipsis ¶
If string is longer than length, return the first length-3 characters and ..., otherwise return the string
func WrapCmd ¶
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 ¶
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 ¶
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 WriteMacAgentStart ¶
func WriteMacAgentStart(appName string)
Types ¶
This section is empty.