types

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetErrNoMatch = func() error {
	return errNoMatch
}
View Source
var Type = &Types{
	Boolean:  &BooleanType{},
	Integer:  &IntegerType{},
	Float:    &FloatType{},
	String:   &StringType{},
	Duration: &DurationType{},
	Json:     &JsonType{},
}

Functions

func GetBooleanProperty

func GetBooleanProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal bool,
) (res bool, err error)

GetBooleanProperty is helper for get boolean property from the getter

func GetDurationProperty

func GetDurationProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal time.Duration,
) (res time.Duration, err error)

GetDurationProperty is helper for get duration property from the getter

func GetFloatProperty

func GetFloatProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal float64,
) (res float64, err error)

GetFloatProperty is helper for get float property from the getter

func GetIntegerProperty

func GetIntegerProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal int64,
) (res int64, err error)

GetIntegerProperty is helper for get integer property from the getter

func GetJsonProperty

func GetJsonProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal json.RawMessage,
) (res json.RawMessage, err error)

GetJsonProperty is helper for get duration property from the getter

func GetStringProperty

func GetStringProperty(
	ctx context.Context,
	getter Getter,
	name string,
	defVal string,
) (res string, err error)

GetStringProperty is helper for get string property from the getter

Types

type BooleanType

type BooleanType struct{}

func (*BooleanType) Cast

func (that *BooleanType) Cast(v interface{}, defaults bool) bool

func (*BooleanType) Get

func (that *BooleanType) Get(ctx context.Context, getter Getter, name string, defVal bool) (res bool, err error)

func (*BooleanType) Is

func (that *BooleanType) Is(value interface{}) bool

func (*BooleanType) TryCast

func (that *BooleanType) TryCast(value interface{}) (bool, bool)

type DurationType

type DurationType struct{}

func (*DurationType) Cast

func (that *DurationType) Cast(v interface{}, defaults time.Duration) time.Duration

func (*DurationType) Get

func (that *DurationType) Get(ctx context.Context, getter Getter, name string, defVal time.Duration) (res time.Duration, err error)

func (*DurationType) Is

func (that *DurationType) Is(value interface{}) bool

func (*DurationType) TryCast

func (that *DurationType) TryCast(value interface{}) (time.Duration, bool)

type FloatType

type FloatType struct{}

func (*FloatType) Cast

func (that *FloatType) Cast(v interface{}, defaults float64) float64

func (*FloatType) Get

func (that *FloatType) Get(ctx context.Context, getter Getter, name string, defVal float64) (res float64, err error)

func (*FloatType) Is

func (that *FloatType) Is(value interface{}) bool

func (*FloatType) TryCast

func (that *FloatType) TryCast(value interface{}) (float64, bool)

type Getter

type Getter interface {
	GetProperty(ctx context.Context, name string) (interface{}, error)
}

Getter is abstract property props

type IntegerType

type IntegerType struct{}

func (*IntegerType) Cast

func (that *IntegerType) Cast(v interface{}, defaults int64) int64

func (*IntegerType) Get

func (that *IntegerType) Get(ctx context.Context, getter Getter, name string, defVal int64) (res int64, err error)

func (*IntegerType) Is

func (that *IntegerType) Is(value interface{}) bool

func (*IntegerType) TryCast

func (that *IntegerType) TryCast(value interface{}) (int64, bool)

type JsonType

type JsonType struct {
}

func (*JsonType) Cast

func (that *JsonType) Cast(v interface{}, defaults json.RawMessage) json.RawMessage

func (*JsonType) Get

func (that *JsonType) Get(ctx context.Context, getter Getter, name string, defVal json.RawMessage) (res json.RawMessage, err error)

func (*JsonType) Is

func (that *JsonType) Is(value interface{}) bool

func (*JsonType) TryCast

func (that *JsonType) TryCast(value interface{}) (json.RawMessage, bool)

type Setter

type Setter interface {
	SetProperty(ctx context.Context, name string, value interface{}) error
}

Setter is abstract property setter

type StringType

type StringType struct{}

func (*StringType) Cast

func (that *StringType) Cast(v interface{}, defaults string) string

func (*StringType) Get

func (that *StringType) Get(ctx context.Context, getter Getter, name string, defVal string) (res string, err error)

func (*StringType) Is

func (that *StringType) Is(value interface{}) bool

func (*StringType) TryCast

func (that *StringType) TryCast(value interface{}) (string, bool)

type TypeChecker

type TypeChecker interface {
	Is(value interface{}) bool
}

type Typer

type Typer[T any] interface {
	TypeChecker
	Get(ctx context.Context, getter Getter, name string, defVal T) (res T, err error)
	TryCast(value interface{}) (T, bool)
	Cast(value interface{}, defVal T) T
}

type Types

type Types struct {
	Boolean  Typer[bool]
	Integer  Typer[int64]
	Float    Typer[float64]
	String   Typer[string]
	Duration Typer[time.Duration]
	Json     Typer[json.RawMessage]
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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