Documentation
¶
Index ¶
- Constants
- func DateBetweenDates(dt timex.Date, start, end timex.Date) bool
- func DefaultHash(s string) string
- func DefaultItemKeysHash(keys []ItemKey) string
- func EllipticalTruncate(text string, maxLen int) string
- func EndingOfMonth(date timex.Date) timex.Date
- func FormatMoney(value float64) string
- func FormatShortDate(dt timex.Date) string
- func FromCivilDate(dt civil.Date) timex.Date
- func IndentJSON(data string) string
- func Ptr[T any](v T) *T
- func RandString(n int) string
- func ShortMonthName(month time.Month) string
- func SortMapByValue[K comparable, V any](m map[K]V, cmp func(V, V) int, reverse bool) iter.Seq2[K, V]
- func SortMapByValueOrdered[K comparable, V cmp.Ordered](m map[K]V, reverse bool) iter.Seq2[K, V]
- func TimeStartEnd(start, end timex.Date) (time.Time, time.Time)
- type Cloud
- type CloudQueryItem
- type EmptyValue
- type Item
- type ItemKey
- type ItemValue
- type Parameter
- type Parameters
- type QueryExtraData
- type QueryExtraOutput
- type QueryFilter
- type QueryGroup
- type QueryHandlerOption
- func WithQueryHandlerFilterKeys(f func(keys []ItemKey) bool) QueryHandlerOption
- func WithQueryHandlerFilters(filters ...QueryFilter) QueryHandlerOption
- func WithQueryHandlerGroups(groups ...QueryGroup) QueryHandlerOption
- func WithQueryHandlerItemKeysHash(f func(keys []ItemKey) string) QueryHandlerOption
- func WithQueryHandlerOnPeriodMatchError(onPeriodMatchError func(item CloudQueryItem, matchCount int) error) QueryHandlerOption
- func WithQueryHandlerPeriodLists(periodList ...QueryPeriodList) QueryHandlerOption
- func WithQueryHandlerPeriods(periods ...QueryPeriod) QueryHandlerOption
- type QueryOption
- func WithQueryDates(start, end timex.Date) QueryOption
- func WithQueryExtraData(extraDataCallback func(data QueryExtraData)) QueryOption
- func WithQueryFilters(filters ...QueryFilter) QueryOption
- func WithQueryGroupByDate(groupByDate bool) QueryOption
- func WithQueryGroups(groups ...QueryGroup) QueryOption
- type QueryOptions
- type QueryPeriod
- type QueryPeriodList
- type QueryResult
- type QueryResultGroup
- type QueryResultPeriod
- type URLQuery
- func (q *URLQuery) Clone() *URLQuery
- func (q *URLQuery) Copy(keyFrom, keyTo string) *URLQuery
- func (q *URLQuery) Get(key string) string
- func (q *URLQuery) Move(keyFrom, keyTo string) *URLQuery
- func (q *URLQuery) Params() iter.Seq2[string, string]
- func (q *URLQuery) Path() string
- func (q *URLQuery) Remove(keys ...string) *URLQuery
- func (q *URLQuery) Set(key, value string) *URLQuery
- func (q *URLQuery) SetFromQuery(query url.Values, keys ...string) *URLQuery
- func (q *URLQuery) SetPath(path string) *URLQuery
- func (q *URLQuery) String() string
- func (q *URLQuery) Swap(key1, key2 string) *URLQuery
- type ValueContext
- type ValueOutput
Constants ¶
const DataSeparator = "|"
const (
DefaultSkipDays = -2 // usually data is fresh only from 2 days ago
)
Variables ¶
This section is empty.
Functions ¶
func DateBetweenDates ¶
DateBetweenDates returns whether the passed date is between start and end.
func DefaultItemKeysHash ¶
DefaultItemKeysHash is the default function for hashing the list of item keys.
func EllipticalTruncate ¶
EllipticalTruncate truncates a string with ellipsis at the end.
func EndingOfMonth ¶
EndingOfMonth returns the last day of the month/year of the passed date.
func FormatShortDate ¶
FormatShortDate formats a date like "Feb 15".
func FromCivilDate ¶
FromCivilDate converts from civil.Date to timex.Date.
func IndentJSON ¶
IndentJSON indents a string containing a JSON.
func ShortMonthName ¶
ShortMonthName returns the 3-letter english month abbreviation.
func SortMapByValue ¶
func SortMapByValue[K comparable, V any](m map[K]V, cmp func(V, V) int, reverse bool) iter.Seq2[K, V]
SortMapByValue sorts a map by value.
func SortMapByValueOrdered ¶
SortMapByValueOrdered sorts a map by value where the value is cmp.Ordered.
func TimeStartEnd ¶
TimeStartEnd converts 2 timex.Date values to 2 time.Time values, with the time part set to 00:00:00 and 23:59:59 respectively.
Types ¶
type Cloud ¶
type Cloud interface { // DaysDelay returns the number of days that the cloud service takes to process cost data. Usually the data // is only reliable on the next day. DaysDelay() int // MaxGroupBy returns the maximum number of groups that the cloud service supports. MaxGroupBy() int // Parameters returns the list of possible filtering and grouping parameter. Parameters() Parameters // ParameterTitle returns the string value of a parameter, or the passed value if unknown. ParameterTitle(id string, defaultValue string) string // Query executes the cost explorer query and returns an iterator for the data. Query(ctx context.Context, options ...QueryOption) iter.Seq2[CloudQueryItem, error] // QueryExtraOutput may return any extra output to be shown after the query data, like extra filters // not available in fields from the main query. QueryExtraOutput(ctx context.Context, extraData []QueryExtraData) QueryExtraOutput }
Cloud is a cloud service abstraction.
type EmptyValue ¶
type EmptyValue struct { }
EmptyValue implements ValueOutput always returning "[EMPTY VALUE]".
func (EmptyValue) Output ¶
func (v EmptyValue) Output(ctx context.Context, vctx ValueContext, uq *URLQuery) (string, error)
type Item ¶
Item contains the keys and values of a single cost explorer item, based on the query groups.
type ItemValue ¶
type ItemValue struct {
Value float64
}
ItemValue is the default item value, a monetary cost.
type Parameter ¶
type Parameter struct { ID string // parameter ID, like "SERVICE". Name string // parameter name, like "Service". MenuTitle string // if set, this will be shown in menus instead of Name. DefaultPriority int // if > 0, sets a priority to select a group if the previous group contains a single item. IsGroup bool // set whether the parameter can be used for grouping. IsGroupFilter bool // if IsGroup==true, sets whether the field value will have a link to filter by its value. IsFilter bool // sets whether the parameter can be used for filtering. HasData bool // sets whether the parameter may contain extra data in its name, separated by DataSeparator. DataRequired bool // if HasData==true, sets whether the parameter always contains data or only sometimes. }
Parameter is the configuration of a filtering and/or grouping parameter available for the cloud service.
type Parameters ¶
type Parameters []Parameter
func (Parameters) DefaultGroup ¶
func (p Parameters) DefaultGroup() Parameter
DefaultGroup returns the parameter which is a group that should be the default group if none was selected.
func (Parameters) FindByGroupDefaultPriority ¶
func (p Parameters) FindByGroupDefaultPriority(priority int) (Parameter, bool)
FindByGroupDefaultPriority finds a parameter which is a group and has the passed default priority.
type QueryExtraData ¶
type QueryExtraData interface {
ExtraDataType() string
}
QueryExtraData is possible extra data to be shown after the main cost table.
type QueryExtraOutput ¶
type QueryExtraOutput interface { Close() ExtraOutputs() iter.Seq2[ValueOutput, error] }
QueryExtraOutput returns a list of possible extra output to be shown after the main cost table.
type QueryFilter ¶
QueryFilter is the ID and value of a filter.
type QueryGroup ¶
QueryGroup is the ID and optional value of a group.
type QueryHandlerOption ¶
type QueryHandlerOption func(options *queryHandlerOptions)
func WithQueryHandlerFilterKeys ¶
func WithQueryHandlerFilterKeys(f func(keys []ItemKey) bool) QueryHandlerOption
WithQueryHandlerFilterKeys sets a function to use for filtering the item keys, if needed.
func WithQueryHandlerFilters ¶
func WithQueryHandlerFilters(filters ...QueryFilter) QueryHandlerOption
WithQueryHandlerFilters sets the filters to use for querying.
func WithQueryHandlerGroups ¶
func WithQueryHandlerGroups(groups ...QueryGroup) QueryHandlerOption
WithQueryHandlerGroups sets the groups to use for querying.
func WithQueryHandlerItemKeysHash ¶
func WithQueryHandlerItemKeysHash(f func(keys []ItemKey) string) QueryHandlerOption
WithQueryHandlerItemKeysHash sets the function to use for hashing the item keys. The default is DefaultItemKeysHash.
func WithQueryHandlerOnPeriodMatchError ¶
func WithQueryHandlerOnPeriodMatchError(onPeriodMatchError func(item CloudQueryItem, matchCount int) error) QueryHandlerOption
WithQueryHandlerOnPeriodMatchError sets a function to handle period mismatches. If the function returns an error, processing is stopped and the error is returned.
func WithQueryHandlerPeriodLists ¶
func WithQueryHandlerPeriodLists(periodList ...QueryPeriodList) QueryHandlerOption
WithQueryHandlerPeriodLists sets a list of period lists to query.
func WithQueryHandlerPeriods ¶
func WithQueryHandlerPeriods(periods ...QueryPeriod) QueryHandlerOption
WithQueryHandlerPeriods adds a list of periods to query.
type QueryOption ¶
type QueryOption func(options *QueryOptions)
func WithQueryDates ¶
func WithQueryDates(start, end timex.Date) QueryOption
WithQueryDates sets the date range to query.
func WithQueryExtraData ¶
func WithQueryExtraData(extraDataCallback func(data QueryExtraData)) QueryOption
WithQueryExtraData sets a callback to receive any possible extra data that the query may return. A list of these values should be sent to [Cloud.QueryExtraOutput] after the main cost query finishes.
func WithQueryFilters ¶
func WithQueryFilters(filters ...QueryFilter) QueryOption
WithQueryFilters sets the filters to use for the query.
func WithQueryGroupByDate ¶
func WithQueryGroupByDate(groupByDate bool) QueryOption
WithQueryGroupByDate sets whether to group by date (day only), ignoring any possible time value.
func WithQueryGroups ¶
func WithQueryGroups(groups ...QueryGroup) QueryOption
WithQueryGroups sets the grouping to use for the query.
type QueryOptions ¶
type QueryOptions struct {
Start, End timex.Date
GroupByDate bool
Groups []QueryGroup
Filters []QueryFilter
ExtraDataCallback func(data QueryExtraData)
}
func ParseQueryOptions ¶
func ParseQueryOptions(options ...QueryOption) (QueryOptions, error)
ParseQueryOptions parses the default query options.
type QueryPeriod ¶
type QueryPeriod struct { ID string // optional ID that can be used by the caller to identify the returned period. Not used by the library. Start, End timex.Date }
QueryPeriod is a single period to query.
func GenerateQueryPeriods ¶
func GenerateQueryPeriods(start, end timex.Date, amount int) []QueryPeriod
GenerateQueryPeriods generates "amount" list of periods of the same number of days as the passed range, one before the other.
func NewQueryPeriod ¶
func NewQueryPeriod(start, end timex.Date) QueryPeriod
func (QueryPeriod) String ¶
func (q QueryPeriod) String() string
String returns a short string representation of the period.
func (QueryPeriod) StringFilter ¶
func (q QueryPeriod) StringFilter() string
StringFilter returns a string representation of the period to be used as a filtering value.
func (QueryPeriod) StringWithDuration ¶
func (q QueryPeriod) StringWithDuration(showDuration bool) string
StringWithDuration may append the duration to the String result.
type QueryPeriodList ¶
type QueryPeriodList struct {
Periods []QueryPeriod
}
QueryPeriodList is a list of periods to query.
type QueryResult ¶
type QueryResult struct { Items []*Item TotalValue float64 Groups []QueryResultGroup PeriodsSameDuration bool Periods []QueryResultPeriod ExtraOutput QueryExtraOutput }
func QueryHandler ¶
func QueryHandler(ctx context.Context, cloud Cloud, options ...QueryHandlerOption) (*QueryResult, error)
QueryHandler handles calling [Cloud.Query] while supporting multiple periods.
type QueryResultGroup ¶
QueryResultGroup is a group that was used to query the results.
func (QueryResultGroup) String ¶
func (q QueryResultGroup) String() string
func (QueryResultGroup) Title ¶
func (q QueryResultGroup) Title(isMenu bool) string
type QueryResultPeriod ¶
type QueryResultPeriod struct { QueryPeriod TotalValue float64 }
QueryResultPeriod is a period that was used to query the results.
type URLQuery ¶
type URLQuery struct {
// contains filtered or unexported fields
}
URLQuery is a URL query builder.
func NewURLQuery ¶
func (*URLQuery) SetFromQuery ¶
type ValueContext ¶
type ValueOutput ¶
type ValueOutput interface {
Output(ctx context.Context, vctx ValueContext, uq *URLQuery) (string, error)
}
ValueOutput allows outputting custom values for cost table columns.