Documentation ¶
Index ¶
- func AESDecrypt(stream []byte, key []byte) ([]byte, error)
- func AESEncrypt(data []byte, key []byte) ([]byte, error)
- func ASCII(b []byte) (string, bool)
- func Antipanic(e *error, label string)
- func Args() []string
- func Assert(condition bool, label string)
- func Blue(items ...interface{})
- func BytesToHex(data []byte) string
- func Check(e error)
- func CompactJSON(input []byte) ([]byte, error)
- func DeleteFile(file string) error
- func Dir() string
- func EdSign(data, publicKey, privateKey []byte) ([]byte, error)
- func EdVerify(data, signature, publicKey []byte) error
- func Executable() string
- func FileExists(file string) bool
- func FolderExists(file string) bool
- func Green(items ...interface{})
- func Hash(data []byte) []byte
- func HashMatch(data []byte, hash []byte) bool
- func HexToBytes(data string) ([]byte, error)
- func Lowercase(s string) string
- func Marshal(payload interface{}) ([]byte, error)
- func MarshalNeat(payload interface{}) ([]byte, error)
- func MkDir(dir string) error
- func NeatJSON(input []byte) ([]byte, error)
- func NewEdKeyPair(seed []byte) ([]byte, []byte, error)
- func Now() uint64
- func Panic(s string)
- func Print(items ...interface{})
- func Printable(b []byte) (string, bool)
- func ProgramName() string
- func Prompt(prompt string) string
- func Purple(items ...interface{})
- func RandomBytes(len int) ([]byte, error)
- func ReadFile(file string) ([]byte, error)
- func Red(items ...interface{})
- func ServeSimple(ln net.Listener, getter func([]string) (int, []byte), ...) error
- func SilentPrompt(prompt string) string
- func Sleep(seconds int)
- func SplitURL(url string) []string
- func StipNonASCII(in string) string
- func String(input interface{}) string
- func StripNonPrintableASCII(in string) string
- func Uint64(input interface{}) (uint64, error)
- func Uppercase(s string) string
- func White(items ...interface{})
- func WriteFile(file string, data []byte) error
- func Yellow(items ...interface{})
- type Client
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AESDecrypt ¶
Decrypts given data using a key. AES256, GCM mode.
func AESEncrypt ¶
Encrypts given data using a key. AES256, GCM mode. Uses crypto/rand for nonce.
func Antipanic ¶
Antipanic - usage: defer Antipanic(&e, "label") at the beginning of any function. Label is usually the name of the function prefixed by its package name, e.g. "package.func". This results in traditionally wrapped errors (mimics errors.Wrap). Main purpose: deferring this function transforms panics into errors when they occur inside the function it was deferred in, and requires only one line. Additionally it allows gung-ho use of panics inside parent function to replace error checking, which can shorten code somewhat (as panics force a return).
func Args ¶
func Args() []string
Returns the command line arguments passed to the program. Omits the first element of os.Args, which is the program's filename.
func Blue ¶
func Blue(items ...interface{})
Prints blue. The first item passed is bolded. Each item gets a new line.
func BytesToHex ¶
BytesToHex Converts byte slice to uppercase hexadecimal string representation
func Check ¶
func Check(e error)
Panics if an error is non-nil. Use after defer Antipanic to shorten code.
func CompactJSON ¶
Takes some json and removes unnecessary whitespace
func DeleteFile ¶
DeleteFile deletes a file (or empty directory) at a given relative path
func EdSign ¶
Signs data using an Ed25519 key pair. While only the private key is needed for signing, this function also verifies the signature using the public key provided and returns an error if verification failed, thus guarding against misuse.
func EdVerify ¶
Verifies that a 64byte signature is a valid Ed25519 signature of given data (of any length) using a 32 byte Ed25519 public key. Error is non-nil only if verification succeeds.
func Executable ¶
func Executable() string
Returns full path + filename of currently running executable
func FileExists ¶
Returns true if a file exists at a given relative path
func FolderExists ¶
Returns true if a folder exists at a given relative path
func Green ¶
func Green(items ...interface{})
Prints green. The first item passed is bolded. Each item gets a new line.
func HashMatch ¶
HashMatch checks if the SHA3-512 of a given byte slice matches a given 64 byte array
func HexToBytes ¶
HexToBytes Converts string to byte slice if it is valid hexadecimal. Slice length is zero on fail.
func MarshalNeat ¶
Takes an object, and turns it into neatly formatted JSON
func MkDir ¶
MkDir Creates a folder with specified relative path + name ('dir') with 0755 permissions
func NewEdKeyPair ¶
Creates a new Ed25519 keypair from a given 32 byte seed. The seed should be generated securely (e.g. using crypto/rand) The returns are public key, then private key. Don't mess up the order.
func Print ¶
func Print(items ...interface{})
Prints normally - does not set or unset any color parameters.
func Printable ¶
Converts binary to printable string - returns false if non-printable characters found
func ProgramName ¶
func ProgramName() string
Returns just the name of the running executable (no path)
func Purple ¶
func Purple(items ...interface{})
Prints magenta. The first item passed is bolded. Each item gets a new line.
func RandomBytes ¶
RandomBytes returns byte slice of length n filled with random data (uses crypto/rand)
func Red ¶
func Red(items ...interface{})
Prints red. The first item passed is bolded. Each item gets a new line.
func ServeSimple ¶
func ServeSimple(ln net.Listener, getter func([]string) (int, []byte), poster func([]string, []byte) (int, []byte)) error
Serve on a given address, and forward GET and POST requests to the separate handlers provided
func SilentPrompt ¶
Displays a prompt to the interface and returns what the user enters. Hides user input from the console. Use for password entry for example.
func String ¶
func String(input interface{}) string
Attmepts to convert an object to string. Tries type assertion to string first, then looks for a .Stringer interface, then handles byte slices and arrays as base64, and finally attempts json marshaling. If none of those workes, returns a string representation of the input's type using reflect package.
func StripNonPrintableASCII ¶
Strips non-printable and non-ascii characters from a string
func Uint64 ¶
Converts certain number types and strings to uint64. Returns an error on failed conversion explaining why.
func White ¶
func White(items ...interface{})
Prints white. The first item passed is bolded. Each item gets a new line.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Wrapper for http client with additional methods
func NewClient ¶
Creates a new Client from an http.Client, with a request timeout in seconds. Changes any negative or zero timeout to 1 second. Passing nil client causes the function to use the default &http.Client{} (then add the timeout)
func (*Client) Get ¶
Classic HTTP Get, returning response body (error if status code outside 200-299 range)
func (*Client) GetStruct ¶
HTTP Get, but immediately unmarshals response body into a struct if 200-299 status. Note that json.Unmarshal requires the responseStruct be passed as a pointer to function properly
func (*Client) Post ¶
Classic HTTP Post, returning response body (error if status code outside 200-299 range)
func (*Client) PostStruct ¶
func (c *Client) PostStruct(url string, requestStruct interface{}, responseStruct interface{}) error
HTTP Post, but automatically marshals a struct as request body, and immediately unmarshals response body into a struct if 200-299 status. Note that json.Unmarshal requires the responseStruct be passed as a pointer to function properly