tableconverter

package
v0.0.0-...-66691d1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("not found")
	ErrAlreadyExists = errors.New("already exists")
)

Functions

func Headers

func Headers(headers []api.Header) func() ([]api.Header, error)

func SingleRowFrom

func SingleRowFrom[E any](f func(e E) (api.Row, error)) func(e E) ([]api.Row, error)

func ZipTables

func ZipTables(tables ...*api.Table) (*api.Table, error)

Types

type Func

type Func[E any] func(e E) (*api.Table, error)

func (Func[E]) ConvertToTable

func (f Func[E]) ConvertToTable(v E) (*api.Table, error)

type Funcs

type Funcs[E any] struct {
	Headers func() ([]api.Header, error)
	Rows    func(e E) ([]api.Row, error)
}

func TemplateTableBuilder

func TemplateTableBuilder[E any](columns ...TemplateTableColumn) Funcs[E]

func (Funcs[E]) ConvertToTable

func (f Funcs[E]) ConvertToTable(v E) (*api.Table, error)

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) ConvertToTable

func (r *Registry) ConvertToTable(e any) (*api.Table, error)

func (*Registry) Delete

func (r *Registry) Delete(tag reflect.Type) error

func (*Registry) Lookup

func (r *Registry) Lookup(tag reflect.Type) (TableConverter[any], error)

func (*Registry) Register

func (r *Registry) Register(tag reflect.Type, conv TableConverter[any]) error

type RegistryBuilder

type RegistryBuilder []func(*Registry) error

func (*RegistryBuilder) AddToRegistry

func (b *RegistryBuilder) AddToRegistry(r *Registry) error

func (*RegistryBuilder) Register

func (b *RegistryBuilder) Register(taggedConvs ...TagAndAnyConverter)

func (*RegistryBuilder) RegisterFunc

func (b *RegistryBuilder) RegisterFunc(funcs ...func(*Registry) error)

type SliceFuncs

type SliceFuncs[E any] Funcs[E]

func (SliceFuncs[E]) ConvertToTable

func (f SliceFuncs[E]) ConvertToTable(es []E) (*api.Table, error)

type TableConverter

type TableConverter[E any] interface {
	ConvertToTable(v E) (*api.Table, error)
}

func StaticTable

func StaticTable[E any](table *api.Table) TableConverter[E]

func Zip

func Zip[E any](convs ...TableConverter[E]) TableConverter[E]

type TagAndAnyConverter

type TagAndAnyConverter struct {
	Tag       reflect.Type
	Converter TableConverter[any]
}

func ToTagAndTypedAny

func ToTagAndTypedAny[E any](conv TableConverter[E]) TagAndAnyConverter

type TaggedAnyTableConverter

type TaggedAnyTableConverter interface {
	TableConverter[any]
	Tag() reflect.Type
}

type TemplateTableColumn

type TemplateTableColumn struct {
	Name     string
	Template *template.Template
}

type TypedAnyConverter

type TypedAnyConverter[E any, TC TableConverter[E]] struct {
	Converter TC
}

func (TypedAnyConverter[E, TC]) ConvertToTable

func (c TypedAnyConverter[E, TC]) ConvertToTable(v any) (*api.Table, error)

Jump to

Keyboard shortcuts

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