codec

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Codecs

func Codecs(notifier func(codec *Codec)) (codecs map[string]*Codec, closer func())

func NewCriteriaBuilder

func NewCriteriaBuilder(ctx context.Context, builder CriteriaBuilder) context.Context

NewCriteriaBuilder creates a new criteria builder context

func Register

func Register(name string, codec *Codec)

func RegisterCodec

func RegisterCodec(name string, codec Instance, at time.Time)

func RegisterFactory

func RegisterFactory(name string, factory Factory, at time.Time)

Types

type Codec

type Codec struct {
	Name               string
	Instance           Instance
	InstanceInsertedAt time.Time
	Factory            Factory
	FactoryInsertedAt  time.Time
}

type Column

type Column interface {
	ColumnName() string
	ColumnType() reflect.Type
	FieldName() string
}

type ColumnsSource

type ColumnsSource interface {
	Column(key string) (Column, bool)
	ColumnName(key string) (string, error)
}

type Config

type Config struct {
	Body       string
	InputType  reflect.Type `json:"-" yaml:"-"`
	Args       []string
	OutputType string
}

type Criteria

type Criteria struct {
	Expression   string
	Placeholders []interface{}
}

type CriteriaBuilder

type CriteriaBuilder interface {
	BuildCriteria(ctx context.Context, value interface{}, options *CriteriaBuilderOptions) (*Criteria, error)
}

func CriteriaBuilderFromContext

func CriteriaBuilderFromContext(ctx context.Context) CriteriaBuilder

CriteriaBuilderFromContext returns criteria builder from context

type CriteriaBuilderOptions

type CriteriaBuilderOptions struct {
	Expression string
	Columns    ColumnsSource
	Parameters ValueGetter
	Selector   Selector
}

type Factory

type Factory interface {
	New(codecConfig *Config, options ...Option) (Instance, error)
}

type Instance

type Instance interface {
	ResultType(inputType reflect.Type) (reflect.Type, error)
	Value(ctx context.Context, raw interface{}, options ...Option) (interface{}, error)
}

type Option

type Option func(o *Options)

Option func to set options

func WithColumnsSource

func WithColumnsSource(columnSource ColumnsSource) Option

WithColumnsSource creates columnSource option

func WithOptions

func WithOptions(options ...interface{}) Option

WithOptions creates untyped options

func WithRecord

func WithRecord(record interface{}) Option

WithRecord creates type record option

func WithSelector

func WithSelector(selector Selector) Option

WithSelector creates selector option

func WithTypeLookup

func WithTypeLookup(fn func(name string) (reflect.Type, error)) Option

WithTypeLookup creates type lookup option

func WithValueGetter

func WithValueGetter(option ValueGetter) Option

WithValueGetter creates value gettter options

func WithValueLookup

func WithValueLookup(fn func(ctx context.Context, name string) (interface{}, error)) Option

WithValueLookup creates value lookup option

type Options

type Options struct {
	LookupType  func(name string) (reflect.Type, error)
	Record      interface{}
	LookupValue func(ctx context.Context, name string) (interface{}, error)
	ColumnsSource
	Selector
	ValueGetter
	Options []interface{}
}

Options represents codec options

func NewOptions

func NewOptions(opts []Option) *Options

NewOptions creates an options

func (*Options) Apply

func (o *Options) Apply(opts []Option)

type Predicate

type Predicate struct {
	Parameter string //name of parameter
	Template  string //predicate template
	Criteria
}

type PredicateHandler

type PredicateHandler interface {
	Compute(ctx context.Context, value interface{}) (*Criteria, error)
}

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(opts ...RegistryOption) *Registry

func (*Registry) Codecs

func (r *Registry) Codecs(notifier func(codec *Codec)) (map[string]*Codec, func())

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (*Codec, error)

func (*Registry) RegisterCodec

func (r *Registry) RegisterCodec(name string, codec *Codec)

func (*Registry) RegisterFactory

func (r *Registry) RegisterFactory(name string, factory Factory, at time.Time)

func (*Registry) RegisterInstance

func (r *Registry) RegisterInstance(name string, instance Instance, at time.Time)

type RegistryOption

type RegistryOption func(registry *Registry)

func WithCodec

func WithCodec(name string, codec Instance, at time.Time) RegistryOption

func WithFactory

func WithFactory(name string, factory Factory, at time.Time) RegistryOption

type Selector

type Selector interface {
	IgnoreRead()
}

type ValueGetter

type ValueGetter interface {
	Value(ctx context.Context, paramName string) (interface{}, error)
}

Jump to

Keyboard shortcuts

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