Small useful pieces of golang code
import (
gc "github.com/untillpro/gochips"
) func Test_Get(t *testing.T) {
err := MyFunc()
gc.FatalIfError(t, err, "Error in MyFunc()")
} gc.Error(args ...interface{})
gc.Info(args ...interface{})
// Adds "..." suffux to argument
gc.Doing("Getting things done")
// Does nothing until you set gc.IsVerbose = true
gc.Verbose(args ...interface{})
}Prefixes:
- Verbose() output is prefixed with
gc.VerbosePrefix = "--- " - Error() output is prefixed with
gc.ErrorPrefix = "*** "
Change default behavior:
var Output func(funcName, s string)- This function is called by default implementation of
Error,Infoetc
- This function is called by default implementation of
- It is possible to redefine all implementations, ref:
func init() {
Doing = implDoing
Info = implInfo
Verbose = implVerbose
Error = implError
Output = implOutput
VerboseWriters = implVerboseWriters
}Piped execution a-la shell
echo README.md | grep README.md | sed s/READ/forgive/:
err := new(PipedExec).
Command("echo", "README.md").WorkingDir("/").
Command("grep", "README.md").
Command("echo", "good").
Run(os.Stdout, os.Stdout)Avoid stdout until gc.IsVerbose is set to true:
err := new(PipedExec).
Command("echo", "README.md").WorkingDir("/").
Command("grep", "README.md").
Command("echo", "good").
Run(gc.VerboseWriters())Ref. also PipedExec_test.go