fields

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Package fields define field types for defining JSON views and models.

Index

Constants

View Source
const (
	ErrBadCalendarDuration   strError = "must be RFC 3339 duration in range year to fraction"
	ErrMixedCalendarDuration strError = "can not combine month or year components with day or time components"
	ErrBadFixedDuration      strError = "must be RFC 3339 duration in range week to fraction"
)

Parsing errors.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateMethod added in v0.3.0

type AggregateMethod uint8
const (
	AggregateDefault AggregateMethod = iota
	AggregateCount
	AggregateMin
	AggregateMax
	AggregateSum
	AggregateAvg
	AggregateStateHistSeconds
	AggregateStateHistPercent
	AggregateStateHistRate
)

func (AggregateMethod) MarshalText added in v0.3.0

func (m AggregateMethod) MarshalText() ([]byte, error)

func (AggregateMethod) String added in v0.3.0

func (m AggregateMethod) String() string

func (*AggregateMethod) UnmarshalText added in v0.3.0

func (m *AggregateMethod) UnmarshalText(data []byte) error

type Annotations

type Annotations map[string]string

func (Annotations) Get

func (m Annotations) Get(key string) string

Get returns the value for the given key or an empty string.

func (*Annotations) Set

func (m *Annotations) Set(key, value string)

Set sets the given annotation value to key.

type Base64

type Base64 []byte

Base64 wraps a slice of bytes in order for it to be represented as an RF 4648 raw URL encoded string (i.e without padding). It's more compact than Hexadecimal.

func (Base64) MarshalText

func (b Base64) MarshalText() ([]byte, error)

func (Base64) String

func (b Base64) String() string

func (*Base64) UnmarshalText

func (b *Base64) UnmarshalText(data []byte) error

type Base64NullZero

type Base64NullZero Base64

Base64NullZero is a variant of Base64 which zero value JSON-encodes to null.

func (Base64NullZero) MarshalJSON

func (zn Base64NullZero) MarshalJSON() ([]byte, error)

func (*Base64NullZero) UnmarshalJSON

func (zn *Base64NullZero) UnmarshalJSON(data []byte) error

type Calculation added in v0.3.0

type Calculation struct {
	Alias   string `json:"alias"`
	Formula string `json:"formula"`
}

type CalendarDuration added in v0.3.0

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

CalendarDuration allows encoding either a fixed duration or a monthly duration as an RFC 3339 duration. Combining months and a fixed duration is not allowed.

func FixedCalendarDuration added in v0.3.0

func FixedCalendarDuration(d time.Duration) CalendarDuration

FixedCalendarDuration returns a duration that spans a fixed duration.

func FixedCalendarDurationNullZero added in v0.3.0

func FixedCalendarDurationNullZero(d time.Duration) CalendarDuration

FixedCalendarDurationNullZero returns a calendar duration that spans a fixed duration. If d is zero, the returned duration would JSON-encode to null.

func MonthDuration added in v0.3.0

func MonthDuration(m int) CalendarDuration

MonthDuration returns a duration that spans a given number of months.

func ParseCalendarDuration added in v0.3.0

func ParseCalendarDuration(s string) (CalendarDuration, error)

ParseCalendarDuration converts text-encoded RFC 3339 duration to its CalendarDuration representation.

func (CalendarDuration) AddToTime added in v0.3.0

func (cd CalendarDuration) AddToTime(t time.Time) time.Time

func (CalendarDuration) AddToTimestamp added in v0.3.0

func (cd CalendarDuration) AddToTimestamp(t Timestamp, loc *time.Location) Timestamp

func (CalendarDuration) Duration added in v0.3.0

func (cd CalendarDuration) Duration() time.Duration

func (CalendarDuration) IsZero added in v0.3.0

func (cd CalendarDuration) IsZero() bool

func (CalendarDuration) MarshalText added in v0.3.0

func (dd CalendarDuration) MarshalText() ([]byte, error)

func (CalendarDuration) Months added in v0.3.0

func (cd CalendarDuration) Months() int

func (CalendarDuration) String added in v0.3.0

func (cd CalendarDuration) String() string

func (*CalendarDuration) UnmarshalText added in v0.3.0

func (cd *CalendarDuration) UnmarshalText(b []byte) error

type CalendarDurationNullZero added in v0.3.0

type CalendarDurationNullZero CalendarDuration

CalendarDurationNullZero is a variant of CalendarDuration that JSON encodes the zero-value to null.

func MonthDurationNullZero added in v0.3.0

func MonthDurationNullZero(m int) CalendarDurationNullZero

MonthDurationNullZero returns a calendar duration that spans a given number of months. If m is zero, the returned duration would JSON-encode to null.

func (CalendarDurationNullZero) AddToTime added in v0.3.0

func (cd CalendarDurationNullZero) AddToTime(t time.Time) time.Time

AddToTime adds the duration to the passed in time.

func (CalendarDurationNullZero) AddToTimestamp added in v0.3.0

func (cd CalendarDurationNullZero) AddToTimestamp(t Timestamp, loc *time.Location) Timestamp

func (CalendarDurationNullZero) IsZero added in v0.3.0

func (cd CalendarDurationNullZero) IsZero() bool

func (CalendarDurationNullZero) MarshalJSON added in v0.3.0

func (cd CalendarDurationNullZero) MarshalJSON() ([]byte, error)

func (CalendarDurationNullZero) String added in v0.3.0

func (cd CalendarDurationNullZero) String() string

func (*CalendarDurationNullZero) UnmarshalJSON added in v0.3.0

func (cd *CalendarDurationNullZero) UnmarshalJSON(data []byte) error

type Comparison added in v0.3.0

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

Comparison allows comparing a particular value with one or more operators. The zero-value is treated equivalent to Equal(null).

func Equal added in v0.3.0

func Equal(v any) Comparison

Equal returns a comparison that match values equal to v. Panics if v is not JSON marshalled into a simple JSON type (string, number, bool or null).

func Greater added in v0.3.0

func Greater(gt any) Comparison

Greater returns a comparison that matches values > gte. Panics if gt is not JSON marshalled into an a sortable JSON type (string or number).

func GreaterOrEqual added in v0.3.0

func GreaterOrEqual(gte any) Comparison

GreaterOrEqual returns a comparison that matches values >= gte. Panics if gte is not JSON marshalled into an a sortable JSON type (string or number).

func In added in v0.3.0

func In[E any](elements ...E) Comparison

In returns a comparison that match values in elements. Panics if any element is not JSON marshalled into an a simple JSON type (string, number, bool or null).

func Less added in v0.3.0

func Less(lt any) Comparison

Less returns a comparison that matches values < lt. Panics if lt is not JSON marshalled into an a sortable JSON type (string or number).

func LessOrEqual added in v0.3.0

func LessOrEqual(lte any) Comparison

LessOrEqual returns a comparison that matches values <= lte. Panics if lte is not JSON marshalled into an a sortable JSON type (string or number).

func MergeOperators added in v0.3.0

func MergeOperators(cmps ...Comparison) Comparison

MergeOperators merges multiple comparisons with different operators together to a single comparison entry.

When conflicting operators ar encountered, the right most value is selected for the result. MergeOperators are resolved based on operator keys, where some initializers have an overlap:

  • Equal and In both uses $in.
  • NotEqual and NotIn both uses $nin.
  • Range and GreaterThanOrEqual both uses $gte.
  • Range and LessThan both uses $lt.

Example valid usage:

MergeOperators(Equal(nil), LessThan(49))        // {"$in":[nil],"$lt":49}
MergeOperators(GreaterOrEqual(0), LessThan(49)) // {"$gte":0,"$lt":49}

Example of conflicting operators:

MergeOperators(Equal(0), In(1, 2))       // {"$in":[1,2]}
MergeOperators(In(1, 2), Equal(nil))     // null
MergeOperators(NotIn(1, 2), NotEqual(0)) // {"$nin":[0]}
MergeOperators(NotEqual(0), NotIn(1, 2)) // {"$nin":[1,2]}

func NotEqual added in v0.3.0

func NotEqual(v any) Comparison

NotEqual returns a comparison that match values not equal to v. Panics if v is not JSON marshalled into a simple JSON type (string, number, bool or null).

func NotIn added in v0.3.0

func NotIn[E any](elements ...E) Comparison

NotIn returns a comparison that match values not in elements. Panics if any element is not JSON marshalled into an a simple JSON type (string, number, bool or null).

func Range added in v0.3.0

func Range(gte, lt any) Comparison

Range is a short-hand for:

MergeComparisons(GreaterThanOrEqual(gte), LessThan(lt))

func Regex added in v0.3.0

func Regex(pattern string) Comparison

Regex returns a comparison that match values that matches the provided regexp pattern.

func (Comparison) MarshalJSON added in v0.3.0

func (c Comparison) MarshalJSON() ([]byte, error)

func (Comparison) String added in v0.3.0

func (cmp Comparison) String() string

func (*Comparison) UnmarshalJSON added in v0.3.0

func (c *Comparison) UnmarshalJSON(data []byte) error

type Comparisons added in v0.3.0

type Comparisons map[string]Comparison

func CompareField added in v0.3.0

func CompareField(path string, cmp Comparison) Comparisons

CompareField returns a new filter comparing a single field path.

type DataFilter added in v0.3.0

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

DataFilter describe a type can return an internal data filter structure. Data filters helps reduce the amount of data that is returned by a method.

func DataAnd added in v0.3.0

func DataAnd(filters ...DataFilter) DataFilter

DataAnd joins one or more data filters with logical and.

func SeriesIn added in v0.3.0

func SeriesIn(keys ...string) DataFilter

SeriesIn return a data filter that reduce the time-series to encode in the final result to the ones that are in the specified list of keys.

func TimeRange added in v0.3.0

func TimeRange(gte, lt time.Time) DataFilter

TimeRange return a TimesFilter that matches times in range [gte,lt).

Be aware of API limits according to how large time ranges you can query with different query resolutions. In order to query larger time windows in a single query, you can increase the width of your rollup duration.

See the API documentation for the method you are calling for more details: https://docs.clarify.io/api/1.1/.

func (DataFilter) MarshalJSON added in v0.3.0

func (q DataFilter) MarshalJSON() ([]byte, error)

func (*DataFilter) UnmarshalJSON added in v0.3.0

func (q *DataFilter) UnmarshalJSON(data []byte) error

type DataQuery added in v0.3.0

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

DataQuery holds a data fields. Although it does not expose any fields, the type can be decoded from and encoded to JSON.

func Data added in v0.3.0

func Data() DataQuery

Data returns a new DataQuery that joins passed in filters with logical AND.

func (DataQuery) Last added in v0.3.0

func (dq DataQuery) Last(n int) DataQuery

Last returns a new data query where only the last n non-empty data-points per series that match the query is included. If n is <= 0, no limit is applied.

func (DataQuery) MarshalJSON added in v0.3.0

func (q DataQuery) MarshalJSON() ([]byte, error)

func (DataQuery) Origin added in v0.3.0

func (dq DataQuery) Origin(o time.Time) DataQuery

Origin returns a new data query with a custom rollup bucket origin. The origin is used by DurationRollup and MonthRollup. This setting takes precedence over the firstDayOfWeek setting passed to DurationRollup.

func (DataQuery) RollupDuration added in v0.3.0

func (dq DataQuery) RollupDuration(d time.Duration, firstDayOfWeek time.Weekday) DataQuery

RollupDuration returns a new data query with a fixed duration bucket rollup.

The default bucket origin is set to time 00:00:00 according to the query time-zone for the first date in 2000 where the weekday matches the firstDayOfWeek parameter.

func (DataQuery) RollupMonths added in v0.3.0

func (dq DataQuery) RollupMonths(months int) DataQuery

RollupMonths returns a new data query with a calendar month bucket rollup.

The default bucket origin is set to time 00:00:00 according to the query time-zone for January 1 year 2000.

func (DataQuery) RollupWindow added in v0.3.0

func (dq DataQuery) RollupWindow() DataQuery

RollupWindow returns a new data query with a window based rollup.

func (DataQuery) TimeZone added in v0.3.0

func (dq DataQuery) TimeZone(name string) DataQuery

TimeZone returns a new data query with TimeZone set to name. The name should contain a valid TZ Database reference, such as "UTC", "Europe/Berlin" or "America/New_York". The default value is "UTC".

See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for available values.

The time zone of a data query affects how the rollup bucket origin is aligned when there is no custom origin provided. If the time-zone location includes daylight saving time adjustments (DST), then resulting bucket times are adjusted according to local clock times if the bucket width is above the DST adjustment offset (normally 1 hour).

func (DataQuery) TimeZoneLocation added in v0.3.0

func (dq DataQuery) TimeZoneLocation(loc *time.Location) DataQuery

TimeZoneLocation returns a new data query with the time-zone set to TZ database name of the passed in loc.

The method is equivalent to dq.TimeZone(loc.String()).

func (*DataQuery) UnmarshalJSON added in v0.3.0

func (q *DataQuery) UnmarshalJSON(data []byte) error

func (DataQuery) Where added in v0.3.0

func (dq DataQuery) Where(filter DataFilter) DataQuery

Where returns a new data query which joins the passed in filter conditions with existing filer conditions using logical and.

type EnumValues

type EnumValues map[int]string

EnumValues maps integer Items values to strings.

func (EnumValues) Clone

func (e EnumValues) Clone() EnumValues

Clone returns a deep clone of the enums structure.

func (EnumValues) MarshalJSON

func (e EnumValues) MarshalJSON() ([]byte, error)

type FixedDuration

type FixedDuration struct {
	time.Duration
}

FixedDuration wraps a time.Duration so that it's JSON encoded as an RFC 3339 duration string.

func AsFixedDuration

func AsFixedDuration(d time.Duration) FixedDuration

AsFixedDuration converts d to a FixedDuration instance.

func (FixedDuration) MarshalText added in v0.3.0

func (d FixedDuration) MarshalText() ([]byte, error)

func (FixedDuration) String

func (d FixedDuration) String() string

func (*FixedDuration) UnmarshalText added in v0.3.0

func (d *FixedDuration) UnmarshalText(b []byte) error

type FixedDurationNullZero added in v0.3.0

type FixedDurationNullZero FixedDuration

FixedDurationNullZero is a variant of FixedDuration that JSON encodes the zero-value as null.

func AsFixedDurationNullZero added in v0.3.0

func AsFixedDurationNullZero(d time.Duration) FixedDurationNullZero

AsFixedDurationNullZero converts d to a FixedDurationNullZero instance.

func ParseFixedDuration

func ParseFixedDuration(s string) (FixedDurationNullZero, error)

ParseFixedDuration parses a RFC 3339 string accepting weeks, days, hours, minute, seconds and fractions.

func (FixedDurationNullZero) MarshalJSON added in v0.3.0

func (d FixedDurationNullZero) MarshalJSON() ([]byte, error)

func (FixedDurationNullZero) String added in v0.3.0

func (d FixedDurationNullZero) String() string

func (*FixedDurationNullZero) UnmarshalJSON added in v0.3.0

func (d *FixedDurationNullZero) UnmarshalJSON(b []byte) error

type Hexadecimal

type Hexadecimal []byte

Hexadecimal wraps a slice of bytes in order for it to be represented as a hexadecimal string when encoded. It is less compact that Base64 encoding.

func (Hexadecimal) MarshalText

func (b Hexadecimal) MarshalText() ([]byte, error)

func (Hexadecimal) String

func (b Hexadecimal) String() string

func (*Hexadecimal) UnmarshalText

func (b *Hexadecimal) UnmarshalText(data []byte) error

type HexadecimalNullZero

type HexadecimalNullZero Hexadecimal

HexadecimalNullZero is a variant of Hexadecimal which zero value JSON-encodes to null.

func (HexadecimalNullZero) MarshalJSON

func (zn HexadecimalNullZero) MarshalJSON() ([]byte, error)

func (*HexadecimalNullZero) UnmarshalJSON

func (zn *HexadecimalNullZero) UnmarshalJSON(data []byte) error

type ItemAggregation added in v0.3.0

type ItemAggregation struct {
	Alias       string          `json:"alias,omitempty"`
	ID          string          `json:"id,omitempty"`
	Aggregation AggregateMethod `json:"aggregation,omitempty"`
	State       int             `json:"state"`
	Lead        int             `json:"lead,omitempty"`
	Lag         int             `json:"lag,omitempty"`
}

func (ItemAggregation) MarshalJSON added in v0.3.0

func (ia ItemAggregation) MarshalJSON() ([]byte, error)

type Labels

type Labels map[string][]string

func (*Labels) Add

func (l *Labels) Add(key string, value string)

Add adds the specified value to the relevant key if it's not already present. The resulting values is a sorted array.

func (Labels) Clone

func (l Labels) Clone() Labels

Clone returns a deep clone of the labels structure.

func (Labels) Get

func (l Labels) Get(key string) []string

Get returns all values for the given key or nil.

func (Labels) MarshalJSON

func (l Labels) MarshalJSON() ([]byte, error)

func (*Labels) Remove

func (l *Labels) Remove(key string, value string)

Remove removes the specified value from the relevant key. If there are no values left for the key, the key is deleted.

func (*Labels) Set

func (l *Labels) Set(key string, values []string)

Set replace the set of values at the given location. Any provided duplicates are automatically removed. If there is no values, the key is deleted.

type Number

type Number float64

Number is a float64 value that JSON encodes the IEEE 754 "not-a-number" value to 'null'.

func (Number) Float64

func (f Number) Float64() float64

func (Number) IsNaN

func (f Number) IsNaN() bool

func (Number) MarshalJSON

func (f Number) MarshalJSON() ([]byte, error)

func (*Number) UnmarshalJSON

func (f *Number) UnmarshalJSON(data []byte) error

type ResourceFilter added in v0.3.0

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

ResourceFilter describe a filter for matching clarify resources.

func And added in v0.3.0

func And(filters ...ResourceFilterType) ResourceFilter

And returns a new resource filter that merges the passed-in filters with logical AND.

func FilterAll added in v0.3.0

func FilterAll() ResourceFilter

FilterAll returns an empty filter, meaning it match all resources.

func Or added in v0.3.0

func Or(filters ...ResourceFilterType) ResourceFilter

Or returns a new resource filter that merges the passed-in filters with logical OR.

func (ResourceFilter) MarshalJSON added in v0.3.0

func (f ResourceFilter) MarshalJSON() ([]byte, error)

func (ResourceFilter) String added in v0.3.0

func (f ResourceFilter) String() string

func (*ResourceFilter) UnmarshalJSON added in v0.3.0

func (f *ResourceFilter) UnmarshalJSON(data []byte) error

type ResourceFilterType added in v0.3.0

type ResourceFilterType interface {
	// contains filtered or unexported methods
}

ResourceFilterType is a sum type of all types that can be converted to a Filter instance. This is a sealed interface which means it cannot be implemented by end-users.

type ResourceQuery added in v0.3.0

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

ResourceQuery holds a resource fields. Although it does not expose any fields, the type can be decoded from and encoded to JSON.

func Query added in v0.3.0

func Query() ResourceQuery

Query returns a new resource query which joins the passed in filters with logical AND.

func (ResourceQuery) GetLimit added in v0.3.0

func (q ResourceQuery) GetLimit() int

GetLimit returns the query limit value.

func (ResourceQuery) GetSkip added in v0.3.0

func (q ResourceQuery) GetSkip() int

GetSkip returns the query skip value.

func (ResourceQuery) Limit added in v0.3.0

func (q ResourceQuery) Limit(n int) ResourceQuery

Limit returns a new query that limits the number of results to n. Set limit to -1 to use the maximum allowed value.

func (ResourceQuery) MarshalJSON added in v0.3.0

func (q ResourceQuery) MarshalJSON() ([]byte, error)

func (ResourceQuery) NextPage added in v0.3.0

func (q ResourceQuery) NextPage() ResourceQuery

NextPage returns a new query where the skip value is incremented by the query limit value.

func (ResourceQuery) Skip added in v0.3.0

func (q ResourceQuery) Skip(n int) ResourceQuery

Skip returns a query that skips the first n entries matching the fields.

func (ResourceQuery) Sort added in v0.3.0

func (q ResourceQuery) Sort(fields ...string) ResourceQuery

Sort returns a new query that sorts results using the provided fields. To get descending sort, prefix the field with a minus (-).

See the API reference documentation to determine which fields are sortable for each resource: https://docs.clarify.io/api/1.1/types/resources.

func (ResourceQuery) Total added in v0.3.0

func (q ResourceQuery) Total(force bool) ResourceQuery

Total returns a query that forces the inclusion of a total count in the response when force is true, or includes it only if it can be calculated for free if force is false.

func (*ResourceQuery) UnmarshalJSON added in v0.3.0

func (q *ResourceQuery) UnmarshalJSON(data []byte) error

func (ResourceQuery) Where added in v0.3.0

Where returns a new query with the given where condition added to existing query non-empty filters with logical AND.

See the API reference documentation to determine which fields are filterable for each resource: https://docs.clarify.io/api/1.1/types/resources.

type Timestamp

type Timestamp int64

Timestamp provides a hashable and comparable alternative to time.Time, stored as microseconds since the epoch.

const (
	// OriginTime defines midnight of the first Monday of year 2000 in the
	// UTC time-zone (2000-01-03T00:00:00Z) as microseconds since the epoch.
	OriginTime Timestamp = 946857600000000
)

func AsTimestamp

func AsTimestamp(t time.Time) Timestamp

AsTimestamp converts a time.Time to Timestamp.

func (Timestamp) Add

func (ts Timestamp) Add(d time.Duration) Timestamp

Add adds the fixed duration to the time-stamp.

func (Timestamp) MarshalText

func (ts Timestamp) MarshalText() ([]byte, error)

func (Timestamp) Sub

func (ts Timestamp) Sub(ts2 Timestamp) time.Duration

Sub returns the differences between ts and ts2 as a fixed duration.

func (Timestamp) Time

func (ts Timestamp) Time() time.Time

Time returns the Timestamp as time.Time.

func (Timestamp) Truncate

func (ts Timestamp) Truncate(d time.Duration) Timestamp

Truncate returns the result of rounding ts down to a multiple of d (since OriginTime). Note that this is not fully equivalent to using Truncate on the time.Time type, as we are deliberately using a different origin.

func (*Timestamp) UnmarshalText

func (ts *Timestamp) UnmarshalText(data []byte) error

Jump to

Keyboard shortcuts

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