Skip to content

Commit

Permalink
feat: don't use go maps package (for v1.20.x compatibility)
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Feb 4, 2024
1 parent 82b17d8 commit a6472ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
20 changes: 20 additions & 0 deletions internal/digest/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (
// Aggregate contains aggregated values by aggregation name.
type Aggregate map[string]float64

func (agg Aggregate) clone() Aggregate {
other := make(Aggregate, len(agg))

for key, value := range agg {
other[key] = value
}

return other
}

// Aggregates contains aggregetes by metric name.
type Aggregates map[string]Aggregate

Expand All @@ -24,3 +34,13 @@ func (a Aggregates) Time() time.Time {

return time.UnixMilli(int64(val))
}

func (a Aggregates) clone() Aggregates {
other := make(Aggregates, len(a))

for key, value := range a {
other[key] = value.clone()
}

return other
}
7 changes: 3 additions & 4 deletions internal/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package digest

import (
"maps"
"time"
)

Expand Down Expand Up @@ -33,9 +32,9 @@ func newDigest(from *Digest) *Digest {
d.Start = from.Start
d.Stop = from.Stop
d.Param = from.Param
d.Cumulative = maps.Clone(from.Cumulative)
d.Snapshot = maps.Clone(from.Snapshot)
d.Metrics = maps.Clone(from.Metrics)
d.Cumulative = from.Cumulative.clone()
d.Snapshot = from.Snapshot.clone()
d.Metrics = from.Metrics.clone()
d.State = from.State
if d.Config == nil {
d.Config = make(map[string]interface{})
Expand Down
10 changes: 10 additions & 0 deletions internal/digest/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ func (mets Metrics) Find(name string) (*Metric, bool) {

return met, found
}

func (mets Metrics) clone() Metrics {
other := make(Metrics, len(mets))

for key, value := range mets {
other[key] = value
}

return other
}

0 comments on commit a6472ca

Please sign in to comment.