aboutsummaryrefslogblamecommitdiffstats
path: root/_examples/common.go
blob: 913cb184986acf51984b4020294f9e0d048ec377 (plain) (tree)
1
2
3
4
5
6


                
             

                 













                                                                           
                                                                          



                                               
                                                                         


                                                  
                                                                         
 
package examples

import (
	"fmt"
	"os"
	"strings"
)

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
	}

	fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err))
	os.Exit(1)
}

func Info(format string, args ...interface{}) {
	fmt.Printf("\x1b[34;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
}

func Warning(format string, args ...interface{}) {
	fmt.Printf("\x1b[36;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
}