package dump
import (
"bytes"
"fmt"
"io"
"os"
"reflect"
"time"
"github.com/gookit/goutil/x/ccolor"
)
const (
Fnopos = 1 << iota
Ffunc
Ffile
Ffname
Fline
)
const defaultSkip = 3
var (
callerFlags = []int {Ffunc , Ffile , Ffname , Fline }
defaultTheme = Theme {
"caller" : "magenta" ,
"field" : "green" ,
"value" : "normal" ,
"msType" : "green" ,
"valTip" : "gray" ,
"string" : "green" ,
"integer" : "lightBlue" ,
}
std = NewDumper (os .Stdout , defaultSkip )
std2 = NewWithOptions (func (opts *Options ) {
opts .Output = os .Stdout
opts .ShowFlag = Fnopos
})
stringerType = reflect .TypeOf ((*fmt .Stringer )(nil )).Elem ()
timeType = reflect .TypeOf (time .Time {})
)
type Theme map [string ]string
func (ct Theme ) caller (s string ) string { return ct .wrap ("caller" , s ) }
func (ct Theme ) field (s string ) string { return ct .wrap ("field" , s ) }
func (ct Theme ) value (s string ) string { return ct .wrap ("value" , s ) }
func (ct Theme ) msType (s string ) string { return ct .wrap ("msType" , s ) }
func (ct Theme ) valTip (s string ) string { return ct .wrap ("valTip" , s ) }
func (ct Theme ) string (s string ) string { return ct .wrap ("string" , s ) }
func (ct Theme ) integer (s string ) string { return ct .wrap ("integer" , s ) }
func (ct Theme ) wrap (key string , s string ) string {
if tag := ct [key ]; tag != "" {
return ccolor .WrapTag (s , tag )
}
return s
}
func Std () *Dumper { return std }
func Reset () { std = NewDumper (os .Stdout , 3 ) }
func Config (fns ...OptionFunc ) { std .WithOptions (fns ...) }
func V (vs ...any ) {
std .Dump (vs ...)
}
func P (vs ...any ) {
std .Print (vs ...)
}
func Print (vs ...any ) {
std .Print (vs ...)
}
func Println (vs ...any ) {
std .Println (vs ...)
}
func Fprint (w io .Writer , vs ...any ) {
std .Fprint (w , vs ...)
}
func Std2 () *Dumper { return std2 }
func Reset2 () {
std2 = NewWithOptions (func (opts *Options ) {
opts .Output = os .Stdout
opts .ShowFlag = Fnopos
})
}
func Format (vs ...any ) string {
w := &bytes .Buffer {}
std2 .Fprint (w , vs ...)
return w .String ()
}
func NoLoc (vs ...any ) {
std2 .Println (vs ...)
}
func Clear (vs ...any ) {
std2 .Println (vs ...)
}
func isUnexported(fieldName string ) bool {
return fieldName [0 ] < 'A' || fieldName [0 ] > 'Z'
}
func isNilOrInvalid(v reflect .Value ) bool {
if !v .IsValid () {
return true
}
switch v .Kind () {
case reflect .Chan , reflect .Func , reflect .Map , reflect .Pointer , reflect .UnsafePointer , reflect .Interface , reflect .Slice :
return v .IsNil ()
default :
return false
}
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .