Documentation ¶
Overview ¶
Package verbose provides a simple package to allow for printing out messages that help you show the flow of how your program works. And you don't have to remove them. Just implement it as a 'flag': verb:=verbose.New() flag.BoolVar(&verb.V, "v", false, "Verbose mode"
Then in your code you can put in your code: func main() { ...code... verb.Println("Database Query:",query) ... code ... verb.Println("Calculating world peace -- this could take some time.", worldPeace) You can leave this in your code, hide that there is a -v option if you want to. But the result is that when things go wrong and inevitably things go wrong, you can see the flow of your program. For information about UTF-8 strings in Go, see https://blog.golang.org/strings.
Index ¶
- func MyTest() string
- func TimeFormatStr(tformat string) (fmtStr string)
- type Verb
- func (v *Verb) Err(err error, str string, e ...bool) bool
- func (v *Verb) ErrOut(err error, str string, e ...bool) bool
- func (verb *Verb) Fprint(w io.Writer, a ...any)
- func (verb *Verb) Fprintf(w io.Writer, format string, a ...any)
- func (verb *Verb) Fprintln(w io.Writer, a ...any)
- func (v *Verb) Print(a ...any)
- func (v *Verb) Printf(format string, a ...any)
- func (v *Verb) Printj(data interface{})
- func (v *Verb) Println(a ...any)
- func (v *Verb) Spin(quit chan bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TimeFormatStr ¶
Converts Unix/Linux date stamp to Go Date Format. date +"%A %d %B %Y, %I:%M:%S %P %Z" Returns: Thursday December 12 2022, 06:03:08 P EST verbose.TimeFormatStr("%A %B %d %Y, %I:%M:%S %P %Z") Returns: "Monday January 02 2006, 03:05:05 PM MST". When put into time.Now().Format("Monday January 02 2006, 03:05:05 PM MST") Would give you: "Thursday December 12 2022, 06:03:08 PM EST"
Types ¶
type Verb ¶
type Verb struct { // V when set to true enables the verbose printing. V bool // set the date format using standard Go Formatting 2006/01/02 15:04:05 Dformat string // Set the delimiter between date, line number and print string. Delimeter string // If set to false, date will not be printed PrintDate bool // If set to false, line number will not be printed PrintLine bool // Set where to write the print statements. By default it's stderr, but you can change it to stdout, or to a file. Out io.Writer `default0:os.Stderr` }
func New ¶
Returns a type Verb and sets some defaults. If nothing passed verbose.New(), no date is used if verbose.New("default") use a default date string. Date string can be customized by either setting Dformat using go date format string or by passing a linux date compatible string to verbose.New.
func (*Verb) ErrOut ¶ added in v1.1.0
err out will always print if an error is present. to only print when verb is true use Err. Prints to whatever verbose.Out is set to.
func (*Verb) Fprint ¶
Just like fmt.Fprint -- only prints when verbose.V is true. Only prints the date and line number if PrintDate and PrintLine are true
func (*Verb) Fprintf ¶
Just like fmt.Fprintf, but only prints if verb.V is true. Only prints the date and line number if PrintDate and PrintLine are true
func (*Verb) Fprintln ¶
Just like fmt.Fprintln -- only prints when verbose.V is true. Only prints the date and line number if PrintDate and PrintLine are true
func (*Verb) Print ¶
Just like fmt.Print -- only prints when verbose.V is true. Only prints the date and line number if PrintDate and PrintLine are true
func (*Verb) Printf ¶
Just like fmt.Printf, but only prints if verb.V is true Only prints the date and line number if PrintDate and PrintLine are true
func (*Verb) Printj ¶ added in v1.2.0
func (v *Verb) Printj(data interface{})
Prints a interface (struct) in indented JSON. Only prints if verb.V is true Line numbers are not printed.