1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-09-16 09:26:25 +02:00
Use
https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize
to update code to new style.

---------

Co-authored-by: Flc゛ <four_leaf_clover@foxmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
Mikhail Mazurskiy
2025-07-29 18:19:11 +10:00
committed by GitHub
parent 7bcbb6a49a
commit 5e1c62a2d5
97 changed files with 234 additions and 268 deletions

View File

@@ -78,7 +78,7 @@ func DefaultEncoder() Encoder {
defaultEncoderOnce.Do(func() {
defaultEncoderInstance = &defaultAttrEncoder{
pool: sync.Pool{
New: func() interface{} {
New: func() any {
return &bytes.Buffer{}
},
},

View File

@@ -12,7 +12,7 @@ import (
)
// BoolSliceValue converts a bool slice into an array with same elements as slice.
func BoolSliceValue(v []bool) interface{} {
func BoolSliceValue(v []bool) any {
var zero bool
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero))).Elem()
reflect.Copy(cp, reflect.ValueOf(v))
@@ -20,7 +20,7 @@ func BoolSliceValue(v []bool) interface{} {
}
// Int64SliceValue converts an int64 slice into an array with same elements as slice.
func Int64SliceValue(v []int64) interface{} {
func Int64SliceValue(v []int64) any {
var zero int64
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero))).Elem()
reflect.Copy(cp, reflect.ValueOf(v))
@@ -28,7 +28,7 @@ func Int64SliceValue(v []int64) interface{} {
}
// Float64SliceValue converts a float64 slice into an array with same elements as slice.
func Float64SliceValue(v []float64) interface{} {
func Float64SliceValue(v []float64) any {
var zero float64
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero))).Elem()
reflect.Copy(cp, reflect.ValueOf(v))
@@ -36,7 +36,7 @@ func Float64SliceValue(v []float64) interface{} {
}
// StringSliceValue converts a string slice into an array with same elements as slice.
func StringSliceValue(v []string) interface{} {
func StringSliceValue(v []string) any {
var zero string
cp := reflect.New(reflect.ArrayOf(len(v), reflect.TypeOf(zero))).Elem()
reflect.Copy(cp, reflect.ValueOf(v))
@@ -44,7 +44,7 @@ func StringSliceValue(v []string) interface{} {
}
// AsBoolSlice converts a bool array into a slice into with same elements as array.
func AsBoolSlice(v interface{}) []bool {
func AsBoolSlice(v any) []bool {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
return nil
@@ -57,7 +57,7 @@ func AsBoolSlice(v interface{}) []bool {
}
// AsInt64Slice converts an int64 array into a slice into with same elements as array.
func AsInt64Slice(v interface{}) []int64 {
func AsInt64Slice(v any) []int64 {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
return nil
@@ -70,7 +70,7 @@ func AsInt64Slice(v interface{}) []int64 {
}
// AsFloat64Slice converts a float64 array into a slice into with same elements as array.
func AsFloat64Slice(v interface{}) []float64 {
func AsFloat64Slice(v any) []float64 {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
return nil
@@ -83,7 +83,7 @@ func AsFloat64Slice(v interface{}) []float64 {
}
// AsStringSlice converts a string array into a slice into with same elements as array.
func AsStringSlice(v interface{}) []string {
func AsStringSlice(v any) []string {
rv := reflect.ValueOf(v)
if rv.Type().Kind() != reflect.Array {
return nil

View File

@@ -8,28 +8,28 @@ import (
"testing"
)
var wrapFloat64SliceValue = func(v interface{}) interface{} {
var wrapFloat64SliceValue = func(v any) any {
if vi, ok := v.([]float64); ok {
return Float64SliceValue(vi)
}
return nil
}
var wrapInt64SliceValue = func(v interface{}) interface{} {
var wrapInt64SliceValue = func(v any) any {
if vi, ok := v.([]int64); ok {
return Int64SliceValue(vi)
}
return nil
}
var wrapBoolSliceValue = func(v interface{}) interface{} {
var wrapBoolSliceValue = func(v any) any {
if vi, ok := v.([]bool); ok {
return BoolSliceValue(vi)
}
return nil
}
var wrapStringSliceValue = func(v interface{}) interface{} {
var wrapStringSliceValue = func(v any) any {
if vi, ok := v.([]string); ok {
return StringSliceValue(vi)
}
@@ -37,21 +37,21 @@ var wrapStringSliceValue = func(v interface{}) interface{} {
}
var (
wrapAsBoolSlice = func(v interface{}) interface{} { return AsBoolSlice(v) }
wrapAsInt64Slice = func(v interface{}) interface{} { return AsInt64Slice(v) }
wrapAsFloat64Slice = func(v interface{}) interface{} { return AsFloat64Slice(v) }
wrapAsStringSlice = func(v interface{}) interface{} { return AsStringSlice(v) }
wrapAsBoolSlice = func(v any) any { return AsBoolSlice(v) }
wrapAsInt64Slice = func(v any) any { return AsInt64Slice(v) }
wrapAsFloat64Slice = func(v any) any { return AsFloat64Slice(v) }
wrapAsStringSlice = func(v any) any { return AsStringSlice(v) }
)
func TestSliceValue(t *testing.T) {
type args struct {
v interface{}
v any
}
tests := []struct {
name string
args args
want interface{}
fn func(interface{}) interface{}
want any
fn func(any) any
}{
{
name: "Float64SliceValue() two items",
@@ -136,7 +136,7 @@ func BenchmarkStringSliceValue(b *testing.B) {
func BenchmarkAsFloat64Slice(b *testing.B) {
b.ReportAllocs()
var in interface{} = [2]float64{1, 2.3}
var in any = [2]float64{1, 2.3}
b.ResetTimer()
for i := 0; i < b.N; i++ {

View File

@@ -40,7 +40,7 @@ func TestDefined(t *testing.T) {
}
func TestJSONValue(t *testing.T) {
var kvs interface{} = [2]attribute.KeyValue{
var kvs any = [2]attribute.KeyValue{
attribute.String("A", "B"),
attribute.Int64("C", 1),
}

View File

@@ -35,7 +35,7 @@ type (
// will return the save value across versions. For this reason, Distinct
// should always be used as a map key instead of a Set.
Distinct struct {
iface interface{}
iface any
}
// Sortable implements sort.Interface, used for sorting KeyValue.
@@ -344,7 +344,7 @@ func computeDistinct(kvs []KeyValue) Distinct {
// computeDistinctFixed computes a Distinct for small slices. It returns nil
// if the input is too large for this code path.
func computeDistinctFixed(kvs []KeyValue) interface{} {
func computeDistinctFixed(kvs []KeyValue) any {
switch len(kvs) {
case 1:
return [1]KeyValue(kvs)
@@ -373,7 +373,7 @@ func computeDistinctFixed(kvs []KeyValue) interface{} {
// computeDistinctReflect computes a Distinct using reflection, works for any
// size input.
func computeDistinctReflect(kvs []KeyValue) interface{} {
func computeDistinctReflect(kvs []KeyValue) any {
at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem()
for i, keyValue := range kvs {
*(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue
@@ -387,7 +387,7 @@ func (l *Set) MarshalJSON() ([]byte, error) {
}
// MarshalLog is the marshaling function used by the logging system to represent this Set.
func (l Set) MarshalLog() interface{} {
func (l Set) MarshalLog() any {
kvs := make(map[string]string)
for _, kv := range l.ToSlice() {
kvs[string(kv.Key)] = kv.Value.Emit()

View File

@@ -22,7 +22,7 @@ type Value struct {
vtype Type
numeric uint64
stringly string
slice interface{}
slice any
}
const (
@@ -199,8 +199,8 @@ func (v Value) asStringSlice() []string {
type unknownValueType struct{}
// AsInterface returns Value's data as interface{}.
func (v Value) AsInterface() interface{} {
// AsInterface returns Value's data as any.
func (v Value) AsInterface() any {
switch v.Type() {
case BOOL:
return v.AsBool()
@@ -262,7 +262,7 @@ func (v Value) Emit() string {
func (v Value) MarshalJSON() ([]byte, error) {
var jsonVal struct {
Type string
Value interface{}
Value any
}
jsonVal.Type = v.Type().String()
jsonVal.Value = v.AsInterface()

View File

@@ -18,7 +18,7 @@ func TestValue(t *testing.T) {
name string
value attribute.Value
wantType attribute.Type
wantValue interface{}
wantValue any
}{
{
name: "Key.Bool() correctly returns keys's internal bool value",