1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Drop support for Go 1.20 (#4967)

* Update README.md

* Remove 1.20 support from CI workflows

* Update all go mod

* Add changelog entry

* Update go mod tidy target

* Run go mod tidy

* Replace sliceEqualFunc with slices.EqualFunc

* Replace grow with slices.Grow

* Replace ensureAttributesCapacity with slices.Grow

* Replace conditional with min

* Use slices module for slice comparison in metricdatatest
This commit is contained in:
Tyler Yahn
2024-02-25 10:48:32 -08:00
committed by GitHub
parent 8fb28b57ce
commit 561714acb2
58 changed files with 178 additions and 160 deletions
+3 -28
View File
@@ -20,6 +20,7 @@ import (
"bytes"
"errors"
"math"
"slices"
"unsafe"
"go.opentelemetry.io/otel/internal/global"
@@ -261,11 +262,9 @@ func (v Value) Equal(w Value) bool {
case KindFloat64:
return v.asFloat64() == w.asFloat64()
case KindSlice:
// TODO: replace with slices.EqualFunc when Go 1.20 support dropped.
return sliceEqualFunc(v.asSlice(), w.asSlice(), Value.Equal)
return slices.EqualFunc(v.asSlice(), w.asSlice(), Value.Equal)
case KindMap:
// TODO: replace with slices.EqualFunc when Go 1.20 support dropped.
return sliceEqualFunc(v.asMap(), w.asMap(), KeyValue.Equal)
return slices.EqualFunc(v.asMap(), w.asMap(), KeyValue.Equal)
case KindBytes:
return bytes.Equal(v.asBytes(), w.asBytes())
case KindEmpty:
@@ -276,30 +275,6 @@ func (v Value) Equal(w Value) bool {
}
}
// sliceEqualFunc reports whether two slices are equal using an equality
// function on each pair of elements. If the lengths are different,
// sliceEqualFunc returns false. Otherwise, the elements are compared in
// increasing index order, and the comparison stops at the first index for
// which eq returns false.
//
// This is based on [EqualFunc]. It was added to provide backwards
// compatibility for Go 1.20. When Go 1.20 is no longer supported it can be
// removed.
//
// EqualFunc: https://pkg.go.dev/slices#EqualFunc
func sliceEqualFunc[T any](s1 []T, s2 []T, eq func(T, T) bool) bool {
if len(s1) != len(s2) {
return false
}
for i, v1 := range s1 {
v2 := s2[i]
if !eq(v1, v2) {
return false
}
}
return true
}
// An KeyValue is a key-value pair used to represent a log attribute (a
// superset of [go.opentelemetry.io/otel/attribute.KeyValue]) and map item.
type KeyValue struct {