From a6197bd8c459c7d10717bd9486c17f6c8b3f7f88 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Tue, 31 Jan 2017 23:09:28 +0100 Subject: documentation changes --- _examples/common.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 _examples/common.go (limited to '_examples/common.go') diff --git a/_examples/common.go b/_examples/common.go new file mode 100644 index 0000000..971b0f6 --- /dev/null +++ b/_examples/common.go @@ -0,0 +1,32 @@ +package examples + +import ( + "os" + "strings" + + "github.com/fatih/color" +) + +func CheckArgs(arg ...string) { + if len(os.Args) < len(arg)+1 { + Warning("Usage: %s %s", os.Args[0], strings.Join(arg, " ")) + os.Exit(1) + } +} + +func CheckIfError(err error) { + if err == nil { + return + } + + color.Red("error: %s", err) + os.Exit(1) +} + +func Info(format string, args ...interface{}) { + color.Blue(format, args...) +} + +func Warning(format string, args ...interface{}) { + color.Cyan(format, args...) +} -- cgit