// Package dump like fmt.Println but more pretty and beautiful print Go values.
package dump import ( ) // These flags define which print caller information const ( Fnopos = 1 << iota // no position Ffunc Ffile Ffname Fline ) const defaultSkip = 3 var ( // valid flag for print caller info callerFlags = []int{Ffunc, Ffile, Ffname, Fline} // default theme defaultTheme = Theme{ "caller": "magenta", "field": "green", // field name color of the map, struct. "value": "normal", // special type "msType": "green", // for keywords map, struct type "valTip": "gray", // tips comments for string, slice, map len "string": "green", "integer": "lightBlue", } // std dumper std = NewDumper(os.Stdout, defaultSkip) // no location dumper. std2 = NewWithOptions(func( *Options) { .Output = os.Stdout .ShowFlag = Fnopos }) // some type init stringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() // time.Time type timeType = reflect.TypeOf(time.Time{}) ) // Theme color code/tag map for dump type Theme map[string]string func ( Theme) ( string) string { return .wrap("caller", ) } func ( Theme) ( string) string { return .wrap("field", ) } func ( Theme) ( string) string { return .wrap("value", ) } func ( Theme) ( string) string { return .wrap("msType", ) } func ( Theme) ( string) string { return .wrap("valTip", ) } func ( Theme) ( string) string { return .wrap("string", ) } func ( Theme) ( string) string { return .wrap("integer", ) } // wrap color tag. func ( Theme) ( string, string) string { if := []; != "" { return ccolor.WrapTag(, ) } return } // Std dumper func () *Dumper { return std } // Reset std dumper func () { std = NewDumper(os.Stdout, 3) } // Config std dumper func ( ...OptionFunc) { std.WithOptions(...) } // V like fmt.Println, but the output is clearer and more beautiful func ( ...any) { std.Dump(...) } // P like fmt.Println, but the output is clearer and more beautiful func ( ...any) { std.Print(...) } // Print like fmt.Println, but the output is clearer and more beautiful func ( ...any) { std.Print(...) } // Println like fmt.Println, but the output is clearer and more beautiful func ( ...any) { std.Println(...) } // Fprint like fmt.Println, but the output is clearer and more beautiful func ( io.Writer, ...any) { std.Fprint(, ...) } // Std2 dumper func () *Dumper { return std2 } // Reset2 reset std2 dumper func () { std2 = NewWithOptions(func( *Options) { .Output = os.Stdout .ShowFlag = Fnopos }) } // Format like fmt.Println, but the output is clearer and more beautiful func ( ...any) string { := &bytes.Buffer{} std2.Fprint(, ...) return .String() } // NoLoc dump vars data, without location. func ( ...any) { std2.Println(...) } // Clear dump clear data, without location. func ( ...any) { std2.Println(...) } // is unexported field name on struct func isUnexported( string) bool { return [0] < 'A' || [0] > 'Z' } func isNilOrInvalid( reflect.Value) bool { if !.IsValid() { return true } switch .Kind() { case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, reflect.Interface, reflect.Slice: return .IsNil() default: return false } }