pprint

package module
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 16 Imported by: 0

README

PrettyPrint module for Go

Inspired by CPython pprint
Installation
go get github.com/goimp/pprint
Docs can be found there

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverInterfaces

func DiscoverInterfaces(structType reflect.Type, interfaces KnownInterface) []reflect.Type

DiscoverInterfaces dynamically finds all interfaces implemented by a given struct.

func GetImplementedInterfacesDescriptor

func GetImplementedInterfacesDescriptor(val reflect.Value, mr Marshalizer) map[string][]string

func GetInterfaceDescriptor

func GetInterfaceDescriptor(typ reflect.Type, mr Marshalizer) []string

func IsReadable

func IsReadable(object any) any

func IsRecurcive

func IsRecurcive(object any) any

func PFormat

func PFormat(
	object any,
	stream io.Writer,
	indent, width, depth int,
	compact, sortMaps, underscoreNumbers bool,
) string

func PP

func PP(
	object any,
	stream io.Writer,
	indent, width, depth int,
	compact, sortMaps, underscoreNumbers bool,
)

func PPrint

func PPrint(
	object any,
	stream io.Writer,
	indent, width, depth int,
	compact, sortMaps, underscoreNumbers bool,
)

func SafeRepr

func SafeRepr(object any) any

func SerializeFuncSignature

func SerializeFuncSignature(val reflect.Value, mr Marshalizer) any

func SerializeMap

func SerializeMap(val reflect.Value, mr Marshalizer) any

func SerializeMethodSignature

func SerializeMethodSignature(method reflect.Method, mr Marshalizer) string

func SerializePointer

func SerializePointer(val reflect.Value, mr Marshalizer) any

func SerializeSlice

func SerializeSlice(val reflect.Value, mr Marshalizer) any

func SerializeStruct

func SerializeStruct(val reflect.Value, mr Marshalizer) any

Types

type Context

type Context map[uintptr]int

func (Context) Contains

func (ctx Context) Contains(objectId uintptr) bool

type DispatchMap

type DispatchMap map[reflect.Kind]pprinter

type InaccessibleField

type InaccessibleField struct {
	Name   string
	Reason string
}

func (InaccessibleField) String

func (i InaccessibleField) String() string

type KindSerializerMap

type KindSerializerMap map[reflect.Kind]Serializer

type KnownInterface

type KnownInterface map[reflect.Type]int

type MappingItem

type MappingItem struct {
	Key   any
	Entry any
}

type Marshalizer

type Marshalizer struct {
	// contains filtered or unexported fields
}

func (Marshalizer) AddKind

func (mr Marshalizer) AddKind(kind reflect.Kind, serializer Serializer)

func (Marshalizer) AddKnownInterface

func (mr Marshalizer) AddKnownInterface(typ reflect.Type)

func (Marshalizer) AddType

func (mr Marshalizer) AddType(typ reflect.Type, serializer Serializer)

func (Marshalizer) RemoveKind

func (mr Marshalizer) RemoveKind(kind reflect.Kind)

func (Marshalizer) RemoveKnownInterface

func (mr Marshalizer) RemoveKnownInterface(typ reflect.Type)

func (Marshalizer) RemoveType

func (mr Marshalizer) RemoveType(typ reflect.Type)

func (Marshalizer) Serialize

func (mr Marshalizer) Serialize(object any) ([]byte, error)

func (Marshalizer) String

func (mr Marshalizer) String() string

type MarshalizerContext

type MarshalizerContext map[uintptr]string

type MarshalizerInterface

type MarshalizerInterface interface {
	Serialize(object any) ([]byte, error)
}

func NewMarshalizer

func NewMarshalizer(includePrivateFields bool, escapeHTML bool, emptyRegistry bool, includeImplements bool) MarshalizerInterface

type PrettyPrinter

type PrettyPrinter struct {
	// contains filtered or unexported fields
}

func (PrettyPrinter) Format

func (pp PrettyPrinter) Format(object any, context Context, maxLevels, level int) (string, bool, bool)

func (PrettyPrinter) IsReadable

func (pp PrettyPrinter) IsReadable(object any) bool

func (PrettyPrinter) IsRecursive

func (pp PrettyPrinter) IsRecursive(object any) bool

func (PrettyPrinter) PFormat

func (pp PrettyPrinter) PFormat(object any) string

func (PrettyPrinter) PPrint

func (pp PrettyPrinter) PPrint(object any)

type PrettyPrinterInterface

type PrettyPrinterInterface interface {
	PPrint(object any)           // +
	PFormat(object any) string   // +
	IsRecursive(object any) bool // +
	IsReadable(object any) bool  // +

	Format(object any, context Context, maxLevels, level int) (string, bool, bool) // +
	// contains filtered or unexported methods
}

func NewPrettyPrinter

func NewPrettyPrinter(
	stream io.Writer,
	indent, width, depth int,
	compact, sortMaps, underscoreNumbers bool,
) (PrettyPrinterInterface, error)

type Serializer

type Serializer func(val reflect.Value, mr Marshalizer) any

type SerializerRegistryInterface

type SerializerRegistryInterface interface {
	AddKind(kind reflect.Kind, serializer Serializer)
	AddType(typ reflect.Type, serializer Serializer)
	AddKnownInterface(typ reflect.Type)
	RemoveKind(kind reflect.Kind)
	RemoveType(typ reflect.Type)
	RemoveKnownInterface(typ reflect.Type)
}

type SerializersRegistry

type SerializersRegistry struct {
	// contains filtered or unexported fields
}

func (SerializersRegistry) AddKind

func (sr SerializersRegistry) AddKind(kind reflect.Kind, serializer Serializer)

func (SerializersRegistry) AddKnownInterface

func (sr SerializersRegistry) AddKnownInterface(typ reflect.Type)

func (SerializersRegistry) AddType

func (sr SerializersRegistry) AddType(typ reflect.Type, serializer Serializer)

func (SerializersRegistry) RemoveKind

func (sr SerializersRegistry) RemoveKind(kind reflect.Kind)

func (SerializersRegistry) RemoveKnownInterface

func (sr SerializersRegistry) RemoveKnownInterface(typ reflect.Type)

func (SerializersRegistry) RemoveType

func (sr SerializersRegistry) RemoveType(typ reflect.Type)

type StructField

type StructField struct {
	Name  string
	Entry any
}

type TypeSerializerMap

type TypeSerializerMap map[reflect.Type]Serializer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL