Documentation
¶
Index ¶
- Constants
- Variables
- func BuildCompiler() string
- func BuildTimestamp() string
- func CompressorNames() []string
- func DecoderNames() []string
- func DecompressorNames() []string
- func DisplayVersion() string
- func EncoderNames() []string
- func FlowNames() []string
- func HttpHandleFunc(config string) http.HandlerFunc
- func InletNames() []string
- func LoadConfig(content string, cfg *PipelineConfig) error
- func NopCloser(w io.Writer) io.WriteCloser
- func OutletNames() []string
- func RegisterCompressor(reg *Compressor)
- func RegisterDecoder(reg *DecoderReg)
- func RegisterDecompressor(reg *Decompressor)
- func RegisterEncoder(reg *EncoderReg)
- func RegisterFlow(reg *FlowReg)
- func RegisterInlet(reg *InletReg)
- func RegisterOutlet(reg *OutletReg)
- func SetDefaultValueFormat(vf ValueFormat)
- func UnboxFields(fields []*Field) []any
- func UnregisterCompressor(name string)
- func UnregisterDecoder(name string)
- func UnregisterDecompressor(name string)
- func UnregisterEncoder(name string)
- func UnregisterFlow(name string)
- func VersionString() string
- type AND
- type Comparator
- type Compressor
- type Config
- func (c Config) GetBool(key string, defaultVal bool) bool
- func (c Config) GetConfig(key string, defaultVal Config) Config
- func (c Config) GetConfigArray(key string, defaultVal []Config) []Config
- func (c Config) GetDuration(key string, defaultVal time.Duration) time.Duration
- func (c Config) GetFloat(key string, defaultVal float64) float64
- func (c Config) GetInt(key string, defaultVal int) int
- func (c Config) GetInt64(key string, defaultVal int64) int64
- func (c Config) GetIntArray(key string, defaultVal []int) []int
- func (c Config) GetString(key string, defaultVal string) string
- func (c Config) GetStringArray(key string, defaultVal []string) []string
- func (c Config) GetUint32(key string, defaultVal uint32) uint32
- func (c Config) Set(key string, val any) Config
- func (c Config) Unset(key string) Config
- type Context
- func (ctx *Context) CircuitBreak()
- func (ctx *Context) Config() Config
- func (ctx *Context) Deadline() (deadline time.Time, ok bool)
- func (ctx *Context) Done() <-chan struct{}
- func (ctx *Context) Err() error
- func (ctx *Context) LogDebug(msg string, keyvals ...interface{})
- func (ctx *Context) LogError(msg string, keyvals ...interface{})
- func (ctx *Context) LogInfo(msg string, keyvals ...interface{})
- func (ctx *Context) LogWarn(msg string, keyvals ...interface{})
- func (ctx *Context) PipelineName() string
- func (ctx *Context) SetContentEncoding(contentEncoding string)
- func (ctx *Context) SetContentLength(contentLength int)
- func (ctx *Context) SetContentType(contentType string)
- func (ctx *Context) Value(key interface{}) interface{}
- func (ctx *Context) WithConfig(conf Config) *Context
- func (ctx *Context) WithLogger(logger *slog.Logger) *Context
- func (ctx *Context) Writer() io.Writer
- type Decoder
- type DecoderConfig
- type DecoderReg
- type Decompressor
- type Encoder
- type EncoderConfig
- type EncoderReg
- type F
- type Field
- func NewBinaryField(name string, value []byte) *Field
- func NewBinaryFieldNull(name string) *Field
- func NewBoolField(name string, value bool) *Field
- func NewBoolFieldNull(name string) *Field
- func NewFloatField(name string, value float64) *Field
- func NewFloatFieldNull(name string) *Field
- func NewIntField(name string, value int64) *Field
- func NewIntFieldNull(name string) *Field
- func NewStringField(name string, value string) *Field
- func NewStringFieldNull(name string) *Field
- func NewTimeField(name string, value time.Time) *Field
- func NewTimeFieldNull(name string) *Field
- func NewUintField(name string, value uint64) *Field
- func NewUintFieldNull(name string) *Field
- func (v *Field) AddTag(key, value string)
- func (f *Field) BinaryField() *Field
- func (f *Field) BoolField() *Field
- func (v *Field) Clone() *Field
- func (f *Field) Convert(to Type) *Field
- func (v *Field) Copy(newName string) *Field
- func (v *Field) DelTag(key string)
- func (f *Field) FloatField() *Field
- func (f *Field) Func(fn func(any) bool) bool
- func (v *Field) GetTag(key string) string
- func (v *Field) GetTagValues(key string) []string
- func (f *Field) IntField() *Field
- func (f *Field) IsNull() bool
- func (v *Field) SetTag(key, value string)
- func (f *Field) String() string
- func (f *Field) StringField() *Field
- func (v *Field) TagNames() []string
- func (f *Field) TimeField() *Field
- func (f *Field) Type() Type
- func (f *Field) UintField() *Field
- type Flow
- type FlowConfig
- type FlowFuncWrap
- type FlowFuncWrapOption
- type FlowHandler
- type FlowReg
- type Inlet
- type InletConfig
- type InletHandler
- type InletPullFuncOption
- type InletPullFuncWrap
- type InletReg
- type Key
- type OR
- type OpenCloser
- type Option
- func WithConfig(conf string) Option
- func WithConfigFile(path string) Option
- func WithConfigTemplate(configTemplate string, data map[string][]string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithName(name string) Option
- func WithSetContentEncodingFunc(fn SetContentEncodingCallback) Option
- func WithSetContentLengthFunc(fn SetContentLengthCallback) Option
- func WithSetContentTypeFunc(fn SetContentTypeCallback) Option
- func WithWriter(w io.Writer) Option
- type Outlet
- type OutletConfig
- type OutletFuncWrap
- type OutletHandler
- type OutletReg
- type Pipeline
- func (p *Pipeline) AddFlow(name string, flow Flow) (*FlowHandler, error)
- func (p *Pipeline) AddInlet(name string, inlet Inlet) (*InletHandler, error)
- func (p *Pipeline) AddOutlet(name string, outlet Outlet) (*OutletHandler, error)
- func (p *Pipeline) Build() (returnErr error)
- func (p *Pipeline) Context() *Context
- func (p *Pipeline) Run() (returnErr error)
- func (p *Pipeline) Start()
- func (p *Pipeline) Stop() error
- type PipelineConfig
- type Predicate
- type PullInlet
- type PushInlet
- type RawValue
- type Reader
- type ReaderOption
- type Record
- type Row
- type SetContentEncodingCallback
- type SetContentLengthCallback
- type SetContentTypeCallback
- type Table
- func (tb *Table[T]) AddColumn(name string, t Type)
- func (tb *Table[T]) AddColumns(names []string, types []Type)
- func (tb *Table[T]) Clear()
- func (tb *Table[T]) Columns() []string
- func (tb *Table[T]) Compact() *Table[T]
- func (tb *Table[T]) Filter(filter Predicate) *Table[T]
- func (tb *Table[T]) Get(k T) *Row[T]
- func (tb *Table[T]) Keys() []T
- func (tb *Table[T]) Len() int
- func (tb *Table[T]) Rows() [][]*Field
- func (tb *Table[T]) Select(fields []string) (*Table[T], error)
- func (tb *Table[T]) Series(colName string) []*Field
- func (tb *Table[T]) SeriesByIdx(colIdx int) []*Field
- func (tb *Table[T]) SeriesFields(colName string) []*Field
- func (tb *Table[T]) SeriesFieldsByIdx(colIdx int) []*Field
- func (tb *Table[T]) Set(k T, fields ...*Field)
- func (tb *Table[T]) Split(filter Predicate) (*Table[T], *Table[T])
- func (tb *Table[T]) Types() []Type
- type Timeformatter
- type Type
- type Value
- func (val *Value) BinaryValue() *Value
- func (val *Value) Bool() (bool, bool)
- func (v *Value) BoolValue() *Value
- func (val *Value) Bytes() ([]byte, bool)
- func (v *Value) Clone() *Value
- func (val *Value) Eq(other any) bool
- func (val *Value) Float64() (float64, bool)
- func (val *Value) FloatValue() *Value
- func (val *Value) Format(vf ValueFormat) string
- func (val *Value) Gt(other any) bool
- func (val *Value) In(other any) bool
- func (val *Value) Int64() (int64, bool)
- func (val *Value) IntValue() *Value
- func (v *Value) IsNull() bool
- func (val *Value) Lt(other any) bool
- func (v *Value) Raw() any
- func (val *Value) String() (string, bool)
- func (f *Value) StringValue() *Value
- func (val *Value) Time() (time.Time, bool)
- func (val *Value) TimeValue() *Value
- func (v *Value) Type() Type
- func (val *Value) Uint64() (uint64, bool)
- func (val *Value) UintValue() *Value
- type ValueFormat
- type Version
- type Writer
Examples ¶
- DefaultValueFormat
- NewValue
- Value.BinaryValue
- Value.Bool
- Value.BoolValue
- Value.Bytes
- Value.Eq (Int_vs_float)
- Value.Eq (String_vs_float)
- Value.Eq (String_vs_string)
- Value.Float64
- Value.FloatValue
- Value.Gt
- Value.Gt (Bool)
- Value.Int64
- Value.IntValue
- Value.Lt
- Value.Lt (Bool)
- Value.String
- Value.StringValue
- Value.Time
- Value.TimeValue
- Value.Uint64
- Value.UintValue
- ValueFormat
- ValueFormat (Epoch)
Constants ¶
const FIELD_INLET = "_in"
const FIELD_TIMESTAMP = "_ts"
Variables ¶
var DefaultConfigString string
var DefaultTimeformatter = &Timeformatter{format: time.RFC3339, loc: time.Local}
Functions ¶
func BuildCompiler ¶
func BuildCompiler() string
func BuildTimestamp ¶
func BuildTimestamp() string
func CompressorNames ¶
func CompressorNames() []string
func DecoderNames ¶
func DecoderNames() []string
func DecompressorNames ¶
func DecompressorNames() []string
func DisplayVersion ¶
func DisplayVersion() string
func EncoderNames ¶
func EncoderNames() []string
func HttpHandleFunc ¶
func HttpHandleFunc(config string) http.HandlerFunc
HttpHandleFunc is a convience function to create a http.HandlerFunc from a pipeline configuration
func InletNames ¶
func InletNames() []string
func LoadConfig ¶
func LoadConfig(content string, cfg *PipelineConfig) error
func OutletNames ¶
func OutletNames() []string
func RegisterCompressor ¶
func RegisterCompressor(reg *Compressor)
func RegisterDecoder ¶
func RegisterDecoder(reg *DecoderReg)
func RegisterDecompressor ¶
func RegisterDecompressor(reg *Decompressor)
func RegisterEncoder ¶
func RegisterEncoder(reg *EncoderReg)
func RegisterFlow ¶
func RegisterFlow(reg *FlowReg)
func RegisterInlet ¶
func RegisterInlet(reg *InletReg)
func RegisterOutlet ¶
func RegisterOutlet(reg *OutletReg)
func SetDefaultValueFormat ¶
func SetDefaultValueFormat(vf ValueFormat)
func UnboxFields ¶
func UnregisterCompressor ¶
func UnregisterCompressor(name string)
func UnregisterDecoder ¶
func UnregisterDecoder(name string)
func UnregisterDecompressor ¶
func UnregisterDecompressor(name string)
func UnregisterEncoder ¶
func UnregisterEncoder(name string)
func UnregisterFlow ¶
func UnregisterFlow(name string)
func VersionString ¶
func VersionString() string
Types ¶
type Comparator ¶
type Comparator string
const ( EQ Comparator = "==" NEQ Comparator = "!=" GT Comparator = ">" GTE Comparator = ">=" LT Comparator = "<" LTE Comparator = "<=" IN Comparator = "in" NOT_IN Comparator = "not in" CompFunc Comparator = "func" )
type Compressor ¶
type Compressor struct {
Name string
Factory func(io.Writer) io.WriteCloser
ContentEncoding string
}
func GetCompressor ¶
func GetCompressor(name string) *Compressor
type Config ¶
func (Config) GetConfigArray ¶
func (Config) GetDuration ¶
func (Config) GetStringArray ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) CircuitBreak ¶
func (ctx *Context) CircuitBreak()
func (*Context) PipelineName ¶
func (*Context) SetContentEncoding ¶
func (*Context) SetContentLength ¶
func (*Context) SetContentType ¶
func (*Context) WithConfig ¶
type DecoderConfig ¶
type DecoderConfig struct {
Reader io.Reader
Timeformatter *Timeformatter
Fields []string
Types []Type
}
type DecoderReg ¶
type DecoderReg struct {
Name string
Factory func(DecoderConfig) Decoder
}
func GetDecoder ¶
func GetDecoder(name string) *DecoderReg
type Decompressor ¶
type Decompressor struct {
Name string
Factory func(io.Reader) io.ReadCloser
}
func GetDecompressor ¶
func GetDecompressor(name string) *Decompressor
type EncoderConfig ¶
type EncoderReg ¶
type EncoderReg struct {
Name string
Factory func(EncoderConfig) Encoder
ContentType string
}
func GetEncoder ¶
func GetEncoder(name string) *EncoderReg
type F ¶
type F struct {
ColName string
Comparator Comparator
Comparando any
}
type Field ¶
type Field struct {
Name string `json:"name"`
Value *Value `json:"value"`
Tags map[string][]string `json:"tags,omitempty"`
}
func NewBinaryField ¶
func NewBinaryFieldNull ¶
func NewBoolField ¶
func NewBoolFieldNull ¶
func NewFloatField ¶
func NewFloatFieldNull ¶
func NewIntField ¶
func NewIntFieldNull ¶
func NewStringField ¶
func NewStringFieldNull ¶
func NewTimeFieldNull ¶
func NewUintField ¶
func NewUintFieldNull ¶
func (*Field) BinaryField ¶
func (*Field) FloatField ¶
func (*Field) GetTagValues ¶
func (*Field) StringField ¶
type Flow ¶
type Flow interface {
OpenCloser
Process([]Record) ([]Record, error)
Parallelism() int
}
func FanOutFlow ¶
func FlowWithFunc ¶
func FlowWithFunc(fn func([]Record) ([]Record, error), opts ...FlowFuncWrapOption) Flow
type FlowConfig ¶
type FlowFuncWrap ¶
type FlowFuncWrap struct {
// contains filtered or unexported fields
}
func (*FlowFuncWrap) Close ¶
func (fw *FlowFuncWrap) Close() error
func (*FlowFuncWrap) Open ¶
func (fw *FlowFuncWrap) Open() error
func (*FlowFuncWrap) Parallelism ¶
func (fw *FlowFuncWrap) Parallelism() int
type FlowFuncWrapOption ¶
type FlowFuncWrapOption func(*FlowFuncWrap)
func WithFlowFuncParallelism ¶
func WithFlowFuncParallelism(parallelism int) FlowFuncWrapOption
type FlowHandler ¶
type FlowHandler struct {
// contains filtered or unexported fields
}
func NewFlowHandler ¶
func NewFlowHandler(ctx *Context, name string, flow Flow) *FlowHandler
func (*FlowHandler) Start ¶
func (fh *FlowHandler) Start() error
func (*FlowHandler) Stop ¶
func (fh *FlowHandler) Stop() error
func (*FlowHandler) Via ¶
func (fh *FlowHandler) Via(next *FlowHandler) *FlowHandler
type FlowReg ¶
func GetFlowRegistry ¶
type Inlet ¶
type Inlet OpenCloser
func InletWithPullFunc ¶
func InletWithPullFunc(fn func() ([]Record, error), opts ...InletPullFuncOption) Inlet
type InletConfig ¶
type InletConfig struct {
Plugin string
Params Config
Flows []FlowConfig
}
type InletHandler ¶
type InletHandler struct {
// contains filtered or unexported fields
}
func NewInletHandler ¶
func (*InletHandler) AddFlow ¶
func (in *InletHandler) AddFlow(flow *FlowHandler)
AddFlow adds a sub-flow to the inlet handler
func (*InletHandler) Run ¶
func (in *InletHandler) Run() error
func (*InletHandler) Start ¶
func (in *InletHandler) Start()
func (*InletHandler) Stop ¶
func (in *InletHandler) Stop()
func (*InletHandler) Via ¶
func (in *InletHandler) Via(flow *FlowHandler) *FlowHandler
Via connects the inlet handler to a flow handler
type InletPullFuncOption ¶
type InletPullFuncOption func(*InletPullFuncWrap)
func WithInterval ¶
func WithInterval(interval time.Duration) InletPullFuncOption
func WithRunCountLimit ¶
func WithRunCountLimit(limit int64) InletPullFuncOption
type InletPullFuncWrap ¶
type InletPullFuncWrap struct {
// contains filtered or unexported fields
}
func (*InletPullFuncWrap) Close ¶
func (in *InletPullFuncWrap) Close() error
func (*InletPullFuncWrap) Interval ¶
func (in *InletPullFuncWrap) Interval() time.Duration
func (*InletPullFuncWrap) Open ¶
func (in *InletPullFuncWrap) Open() error
func (*InletPullFuncWrap) Pull ¶
func (in *InletPullFuncWrap) Pull() ([]Record, error)
type InletReg ¶
func GetInletRegistry ¶
type OpenCloser ¶
type Option ¶
func WithConfig ¶
WithConfig loads a TOML configuration string into a PipelineConfig struct
func WithConfigFile ¶
WithConfigFile loads a TOML configuration file into a PipelineConfig struct
func WithConfigTemplate ¶
WithConfigTemplate loads a TOML configuration template into a PipelineConfig struct
func WithLogger ¶
WithLogger sets the logger for the pipeline
func WithSetContentEncodingFunc ¶
func WithSetContentEncodingFunc(fn SetContentEncodingCallback) Option
WithSetContentEncodingFunc sets the callback function to set the content encoding
func WithSetContentLengthFunc ¶
func WithSetContentLengthFunc(fn SetContentLengthCallback) Option
WithSetContentLengthFunc sets the callback function to set the content length
func WithSetContentTypeFunc ¶
func WithSetContentTypeFunc(fn SetContentTypeCallback) Option
WithSetContentTypeFunc sets the callback function to set the content type
func WithWriter ¶
WithDefaults sets the default output writer for the pipeline
type OutletConfig ¶
type OutletFuncWrap ¶
type OutletFuncWrap struct {
// contains filtered or unexported fields
}
func (*OutletFuncWrap) Close ¶
func (out *OutletFuncWrap) Close() error
func (*OutletFuncWrap) Handle ¶
func (out *OutletFuncWrap) Handle(r []Record) error
func (*OutletFuncWrap) Open ¶
func (out *OutletFuncWrap) Open() error
type OutletHandler ¶
type OutletHandler struct {
// contains filtered or unexported fields
}
func NewOutletHandler ¶
func NewOutletHandler(ctx *Context, name string, outlet Outlet) (*OutletHandler, error)
func (*OutletHandler) Sink ¶
func (out *OutletHandler) Sink() chan<- []Record
func (*OutletHandler) Start ¶
func (out *OutletHandler) Start() error
func (*OutletHandler) Stop ¶
func (out *OutletHandler) Stop()
type OutletReg ¶
func GetOutletRegistry ¶
type Pipeline ¶
type Pipeline struct {
PipelineConfig
// contains filtered or unexported fields
}
func (*Pipeline) AddFlow ¶
func (p *Pipeline) AddFlow(name string, flow Flow) (*FlowHandler, error)
AddFlow adds a flow to the pipeline
func (*Pipeline) AddInlet ¶
func (p *Pipeline) AddInlet(name string, inlet Inlet) (*InletHandler, error)
AddInlet adds an inlet to the pipeline
func (*Pipeline) AddOutlet ¶
func (p *Pipeline) AddOutlet(name string, outlet Outlet) (*OutletHandler, error)
AddOutlet adds an outlet to the pipeline
func (*Pipeline) Run ¶
Run the pipeline, this will start all inlets, outlets and flows and wait until the pipeline is stopped
type PipelineConfig ¶
type PipelineConfig struct {
Name string
Log util.LogConfig
Defaults Config
Inlets []InletConfig
Outlets []OutletConfig
Flows []FlowConfig
}
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func NewReader ¶
func NewReader(opts ...ReaderOption) (*Reader, error)
type ReaderOption ¶
type ReaderOption func(*Reader)
func WithReader ¶
func WithReader(r io.Reader) ReaderOption
func WithReaderConfig ¶
func WithReaderConfig(cfg Config) ReaderOption
type Record ¶
type Record interface {
// Field retursn field by name
Field(name string) *Field
// Fields returns fields in the order of names
// if names is empty, return all fields
Fields(names ...string) []*Field
// FieldAt returns field by index
FieldAt(index int) *Field
// FieldsAt return fields in the order of indexes
FieldsAt(indexes ...int) []*Field
// Empty returns true if the record has no fields
Empty() bool
// Names returns all field names
Names() []string
// Append returns a new record with fields appended
Append(...*Field) Record
// AppendOrReplace returns a new record with fields appended or replaced if the field name already exists
AppendOrReplace(...*Field) Record
}
type SetContentEncodingCallback ¶
type SetContentEncodingCallback func(contentEncoding string)
type SetContentLengthCallback ¶
type SetContentLengthCallback func(contentLength int)
type SetContentTypeCallback ¶
type SetContentTypeCallback func(contentType string)
type Table ¶
type Table[T Key] struct { // contains filtered or unexported fields }
func (*Table[T]) AddColumns ¶
AddColumns adds columns to the table
names and types should be same size, otherwise panic
func (*Table[T]) Compact ¶
Compact compacts records by predicate it removes records that do not match the predicate if predicate is nil, it does nothing. and returns the table itself. so that chain calls are possible.
tb := tb.Filter(...).Compact().Select(...)
func (*Table[T]) SeriesByIdx ¶
SeriesByIdx returns a series of a column by index
func (*Table[T]) SeriesFields ¶
SeriesFields returns a series of a column by name
func (*Table[T]) SeriesFieldsByIdx ¶
SeriesFieldsByIdx returns a series of a column by index
type Timeformatter ¶
type Timeformatter struct {
// contains filtered or unexported fields
}
func NewTimeformatter ¶
func NewTimeformatter(format string) *Timeformatter
func NewTimeformatterWithLocation ¶
func NewTimeformatterWithLocation(format string, tz *time.Location) *Timeformatter
func (*Timeformatter) IsEpoch ¶
func (tf *Timeformatter) IsEpoch() bool
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func NewNullValue ¶
func NewUntypedNullValue ¶
func NewUntypedNullValue() *Value
func NewValue ¶
Example ¶
var df = DefaultValueFormat()
var v, nv *Value
v = NewValue("string")
nv = NewNullValue(STRING)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue(int64(-123))
nv = NewNullValue(INT)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue(uint64(123))
nv = NewNullValue(UINT)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue(float64(3.141592))
nv = NewNullValue(FLOAT)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue(true)
nv = NewNullValue(BOOL)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue(time.Unix(1721865054, 0))
nv = NewNullValue(TIME)
fmt.Println(v.Format(df), nv.Format(df))
v = NewValue([]byte("binary"))
nv = NewNullValue(BINARY)
fmt.Println(v.Format(df), nv.Format(df))
Output: string NULL -123 NULL 123 NULL 3.141592 NULL true NULL 2024-07-24T23:50:54Z NULL BINARY(6 B) NULL
func (*Value) BinaryValue ¶
BinaryValue returns the binary value of the value. It will return a NewNullValue(BINARY) if it can not be converted to binary.
Example ¶
v := NewValue("binary")
bv := v.BinaryValue()
fmt.Println(hex.EncodeToString(bv.Raw().([]byte)))
Output: 62696e617279
func (*Value) Bool ¶
Example ¶
sv := NewValue("TRUE")
bv, ok := sv.Bool()
fmt.Println(bv, ok)
Output: true true
func (*Value) BoolValue ¶
BoolValue returns the bool value of the value. It will return a NewNullValue(BOOL) if it can not be converted to bool.
Example ¶
sv := NewValue("TRUE")
bv := sv.BoolValue()
fmt.Println(bv.Format(DefaultValueFormat()))
Output: true
func (*Value) Bytes ¶
Example ¶
v := NewValue("binary")
bv, ok := v.Bytes()
fmt.Println(hex.EncodeToString(bv), ok)
Output: 62696e617279 true
func (*Value) Eq ¶
Compare this value with other primitive type If other is nil, the result is not defined.
Example (Int_vs_float) ¶
v1 := NewValue(int64(123)) v2 := NewValue(123.0) fmt.Println(v1.Eq(v2), v1.Eq(123), v1.Eq(123.0), v1.Eq(123.4))
Output: true true true false
Example (String_vs_float) ¶
v1 := NewValue("123.456")
v2 := NewValue(123.456)
v3 := v2.StringValue()
fmt.Println(v1.Eq(v2), v1.Eq(v3), v2.Eq("123.456"))
Output: true true true
Example (String_vs_string) ¶
v1 := NewValue("string")
v2 := NewValue("string")
fmt.Println(v1.Eq(v2), v1.Eq("string"), v1.Eq("not"))
Output: true true false
func (*Value) Float64 ¶
Example ¶
sv := NewValue("3.141592")
iv, ok := sv.Float64()
fmt.Println(iv, ok)
Output: 3.141592 true
func (*Value) FloatValue ¶
FloatValue returns the float value of the value. It will return a NewNullValue(FLOAT) if it can not be converted to float.
Example ¶
sv := NewValue("3.141592")
iv := sv.FloatValue()
fmt.Println(iv.Format(DefaultValueFormat()))
Output: 3.141592
func (*Value) Format ¶
func (val *Value) Format(vf ValueFormat) string
func (*Value) Gt ¶
Compare this value with other primitive type If other is nil, the result is not defined.
Example ¶
v1 := NewValue(int64(123)) v2 := NewValue(234.0) v3 := NewValue(345.4) fmt.Println(v2.Gt(v1), v1.Gt(v3), v3.Gt(v2))
Output: true false true
Example (Bool) ¶
v1 := NewValue(true) v2 := NewValue(false) fmt.Println(v1.Gt(v2))
Output: true
func (*Value) Int64 ¶
Example ¶
sv := NewValue("123")
iv, ok := sv.Int64()
fmt.Println(iv, ok)
Output: 123 true
func (*Value) IntValue ¶
IntValue returns the int value of the value. It will return a NewNullValue(INT) if it can not be converted to int.
Example ¶
sv := NewValue("123")
iv := sv.IntValue()
fmt.Println(iv.Format(DefaultValueFormat()))
Output: 123
func (*Value) Lt ¶
Compare this value with other primitive type If other is nil, the result is not defined.
Example ¶
v1 := NewValue(int64(123)) v2 := NewValue(234.0) v3 := NewValue(345.4) fmt.Println(v2.Lt(v1), v1.Lt(v2), v3.Lt(v2), v1.Lt(v3))
Output: false true false true
Example (Bool) ¶
v1 := NewValue(true) v2 := NewValue(true) fmt.Println(v2.Lt(v1))
Output: true
func (*Value) String ¶
Example ¶
v := NewValue(123.456) sv, ok := v.String() fmt.Println(sv, ok)
Output: 123.456 true
func (*Value) StringValue ¶
StringValue returns the string value of the value. It will return a NewNullValue(STRING) if it can not be converted to string.
Example ¶
v := NewValue(123.456) sv := v.StringValue() fmt.Println(sv.Format(DefaultValueFormat()))
Output: 123.456
func (*Value) Time ¶
Example ¶
v := NewValue(int64(1721865054)) tv, ok := v.Time() fmt.Println(tv.Unix(), ok)
Output: 1721865054 true
func (*Value) TimeValue ¶
TimeValue returns the time value of the value. It will return a NewNullValue(TIME) if it can not be converted to time.
Example ¶
v := NewValue(int64(1721865054)) tv := v.TimeValue() fmt.Println(tv.Format(DefaultValueFormat()))
Output: 2024-07-24T23:50:54Z
type ValueFormat ¶
type ValueFormat struct {
Timeformat *Timeformatter
Decimal int
NullString string
NullInt int
NullFloat float64
NullTime time.Time
NullBool bool
}
Example ¶
tm := time.Unix(1721865054, 0)
vf := DefaultValueFormat()
vf.Timeformat = NewTimeformatterWithLocation("2006-01-02 15:04:05", time.UTC)
vf.Decimal = 2
fmt.Println(NewValue(tm).Format(vf), NewValue(3.141592).Format(vf))
Output: 2024-07-24 23:50:54 3.14
Example (Epoch) ¶
tm := time.Unix(1721865054, 0)
vf := DefaultValueFormat()
vf.Timeformat = NewTimeformatter("s")
vf.Decimal = 4
fmt.Println(NewValue(tm).Format(vf), NewValue(3.141592).Format(vf))
Output: 1721865054 3.1416
func DefaultValueFormat ¶
func DefaultValueFormat() ValueFormat
Example ¶
tm := time.Unix(1721865054, 0) vf := DefaultValueFormat() fmt.Println(NewValue(tm).Format(vf), NewValue(3.141592).Format(vf))
Output: 2024-07-24T23:50:54Z 3.141592
func (ValueFormat) FormatTime ¶
func (fo ValueFormat) FormatTime(tm time.Time) string
type Version ¶
type Version struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
GitSHA string `json:"git"`
}
func GetVersion ¶
func GetVersion() *Version