[chore] replace the usage of interface{} with any (#7053)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
Bogdan Drutu 2023-01-30 15:01:25 -08:00 committed by GitHub
parent 26bd7b2bf6
commit a2f0153679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 315 additions and 318 deletions

View File

@ -125,7 +125,7 @@ type AuthData interface {
// implementations might define different data types for different
// attributes. While "string" is used most of the time, a key named
// "membership" might return a list of strings.
GetAttribute(string) interface{}
GetAttribute(string) any
// GetAttributes returns the names of all attributes in this authentication
// data.

View File

@ -82,7 +82,7 @@ type exampleAuthData struct {
username string
}
func (e *exampleAuthData) GetAttribute(key string) interface{} {
func (e *exampleAuthData) GetAttribute(key string) any {
if key == "username" {
return e.username
}

View File

@ -143,7 +143,7 @@ func GetModules(cfg Config) error {
return fmt.Errorf("failed to download go modules: %s", failReason)
}
func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplParams interface{}) error {
func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplParams any) error {
out, err := os.Create(filepath.Clean(filepath.Join(cfg.Distribution.OutputPath, outFile)))
if err != nil {
return err

View File

@ -31,7 +31,7 @@ var configFieldTagRegExp = regexp.MustCompile("^[a-z0-9][a-z0-9_]*$")
// of components and extensions. It is recommended for implementers of components
// to call this function on their tests passing the default configuration of the
// component factory.
func CheckConfigStruct(config interface{}) error {
func CheckConfigStruct(config any) error {
t := reflect.TypeOf(config)
if t.Kind() == reflect.Ptr {
t = t.Elem()

View File

@ -38,7 +38,7 @@ func TestCheckConfigStruct(t *testing.T) {
tests := []struct {
name string
config interface{}
config any
wantErrMsgSubStr string
}{
{

View File

@ -29,7 +29,7 @@ import (
// (e.g. check if a required field is present).
//
// A valid implementation MUST pass the check componenttest.CheckConfigStruct (return nil error).
type Config interface{}
type Config any
// As interface types are only used for static typing, a common idiom to find the reflection Type
// for an interface type Foo is to use a *Foo value.

View File

@ -363,10 +363,10 @@ func (gss *GRPCServerSettings) toServerOption(host component.Host, settings comp
return nil, err
}
uInterceptors = append(uInterceptors, func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
uInterceptors = append(uInterceptors, func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
return authUnaryServerInterceptor(ctx, req, info, handler, authenticator)
})
sInterceptors = append(sInterceptors, func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
sInterceptors = append(sInterceptors, func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return authStreamServerInterceptor(srv, ss, info, handler, authenticator)
})
}
@ -406,14 +406,14 @@ func getGRPCCompressionName(compressionType configcompression.CompressionType) (
// enhanceWithClientInformation intercepts the incoming RPC, replacing the incoming context with one that includes
// a client.Info, potentially with the peer's address.
func enhanceWithClientInformation(includeMetadata bool) func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
func enhanceWithClientInformation(includeMetadata bool) func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
return handler(contextWithClient(ctx, includeMetadata), req)
}
}
func enhanceStreamWithClientInformation(includeMetadata bool) func(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return func(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
func enhanceStreamWithClientInformation(includeMetadata bool) func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return handler(srv, wrapServerStream(contextWithClient(ss.Context(), includeMetadata), ss))
}
}
@ -437,7 +437,7 @@ func contextWithClient(ctx context.Context, includeMetadata bool) context.Contex
return client.NewContext(ctx, cl)
}
func authUnaryServerInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, server auth.Server) (interface{}, error) {
func authUnaryServerInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler, server auth.Server) (any, error) {
headers, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, errMetadataNotFound
@ -451,7 +451,7 @@ func authUnaryServerInterceptor(ctx context.Context, req interface{}, _ *grpc.Un
return handler(ctx, req)
}
func authStreamServerInterceptor(srv interface{}, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, server auth.Server) error {
func authStreamServerInterceptor(srv any, stream grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler, server auth.Server) error {
ctx := stream.Context()
headers, ok := metadata.FromIncomingContext(ctx)
if !ok {

View File

@ -98,19 +98,19 @@ func compress(compressor encoding.Compressor, in []byte) ([]byte, error) {
type testPayload struct {
name string
message interface{}
message any
marshaler marshaler
}
type marshaler interface {
marshal(interface{}) ([]byte, error)
marshal(any) ([]byte, error)
}
type logMarshaler struct {
plog.Marshaler
}
func (m *logMarshaler) marshal(e interface{}) ([]byte, error) {
func (m *logMarshaler) marshal(e any) ([]byte, error) {
return m.MarshalLogs(e.(plog.Logs))
}
@ -118,7 +118,7 @@ type traceMarshaler struct {
ptrace.Marshaler
}
func (m *traceMarshaler) marshal(e interface{}) ([]byte, error) {
func (m *traceMarshaler) marshal(e any) ([]byte, error) {
return m.MarshalTraces(e.(ptrace.Traces))
}
@ -126,7 +126,7 @@ type metricsMarshaler struct {
pmetric.Marshaler
}
func (m *metricsMarshaler) marshal(e interface{}) ([]byte, error) {
func (m *metricsMarshaler) marshal(e any) ([]byte, error) {
return m.MarshalMetrics(e.(pmetric.Metrics))
}

View File

@ -796,7 +796,7 @@ func TestStreamInterceptorEnhancesClient(t *testing.T) {
ctx: inCtx,
}
handler := func(srv interface{}, stream grpc.ServerStream) error {
handler := func(srv any, stream grpc.ServerStream) error {
outContext = stream.Context()
return nil
}
@ -910,7 +910,7 @@ func TestDefaultUnaryInterceptorAuthSucceeded(t *testing.T) {
return ctx, nil
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
handlerCalled = true
cl := client.FromContext(ctx)
assert.Equal(t, "1.2.3.4", cl.Addr.String())
@ -936,7 +936,7 @@ func TestDefaultUnaryInterceptorAuthFailure(t *testing.T) {
authCalled = true
return context.Background(), expectedErr
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
assert.FailNow(t, "the handler should not have been called on auth failure!")
return nil, nil
}
@ -957,7 +957,7 @@ func TestDefaultUnaryInterceptorMissingMetadata(t *testing.T) {
assert.FailNow(t, "the auth func should not have been called!")
return context.Background(), nil
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
assert.FailNow(t, "the handler should not have been called!")
return nil, nil
}
@ -981,7 +981,7 @@ func TestDefaultStreamInterceptorAuthSucceeded(t *testing.T) {
})
return ctx, nil
}
handler := func(srv interface{}, stream grpc.ServerStream) error {
handler := func(srv any, stream grpc.ServerStream) error {
// ensure that the client information is propagated down to the underlying stream
cl := client.FromContext(stream.Context())
assert.Equal(t, "1.2.3.4", cl.Addr.String())
@ -1010,7 +1010,7 @@ func TestDefaultStreamInterceptorAuthFailure(t *testing.T) {
authCalled = true
return context.Background(), expectedErr
}
handler := func(srv interface{}, stream grpc.ServerStream) error {
handler := func(srv any, stream grpc.ServerStream) error {
assert.FailNow(t, "the handler should not have been called on auth failure!")
return nil
}
@ -1033,7 +1033,7 @@ func TestDefaultStreamInterceptorMissingMetadata(t *testing.T) {
assert.FailNow(t, "the auth func should not have been called!")
return context.Background(), nil
}
handler := func(srv interface{}, stream grpc.ServerStream) error {
handler := func(srv any, stream grpc.ServerStream) error {
assert.FailNow(t, "the handler should not have been called!")
return nil
}

View File

@ -37,8 +37,8 @@ func New() *Conf {
return &Conf{k: koanf.New(KeyDelimiter)}
}
// NewFromStringMap creates a confmap.Conf from a map[string]interface{}.
func NewFromStringMap(data map[string]interface{}) *Conf {
// NewFromStringMap creates a confmap.Conf from a map[string]any.
func NewFromStringMap(data map[string]any) *Conf {
p := New()
// Cannot return error because the koanf instance is empty.
_ = p.k.Load(confmap.Provider(data, KeyDelimiter), nil)
@ -82,7 +82,7 @@ func (fn unmarshalOptionFunc) apply(set *unmarshalOption) {
// Unmarshal unmarshalls the config into a struct using the given options.
// Tags on the fields of the structure must be properly set.
func (l *Conf) Unmarshal(result interface{}, opts ...UnmarshalOption) error {
func (l *Conf) Unmarshal(result any, opts ...UnmarshalOption) error {
set := unmarshalOption{}
for _, opt := range opts {
opt.apply(&set)
@ -97,13 +97,13 @@ type MarshalOption interface {
}
// Marshal encodes the config and merges it into the Conf.
func (l *Conf) Marshal(rawVal interface{}, _ ...MarshalOption) error {
func (l *Conf) Marshal(rawVal any, _ ...MarshalOption) error {
enc := encoder.New(encoderConfig(rawVal))
data, err := enc.Encode(rawVal)
if err != nil {
return err
}
out, ok := data.(map[string]interface{})
out, ok := data.(map[string]any)
if !ok {
return fmt.Errorf("invalid config encoding")
}
@ -111,7 +111,7 @@ func (l *Conf) Marshal(rawVal interface{}, _ ...MarshalOption) error {
}
// Get can retrieve any value given the key to use.
func (l *Conf) Get(key string) interface{} {
func (l *Conf) Get(key string) any {
return l.k.Get(key)
}
@ -128,7 +128,7 @@ func (l *Conf) Merge(in *Conf) error {
}
// Sub returns new Conf instance representing a sub-config of this instance.
// It returns an error is the sub-config is not a map[string]interface{} (use Get()), and an empty Map if none exists.
// It returns an error is the sub-config is not a map[string]any (use Get()), and an empty Map if none exists.
func (l *Conf) Sub(key string) (*Conf, error) {
// Code inspired by the koanf "Cut" func, but returns an error instead of empty map for unsupported sub-config type.
data := l.Get(key)
@ -136,15 +136,15 @@ func (l *Conf) Sub(key string) (*Conf, error) {
return New(), nil
}
if v, ok := data.(map[string]interface{}); ok {
if v, ok := data.(map[string]any); ok {
return NewFromStringMap(v), nil
}
return nil, fmt.Errorf("unexpected sub-config value kind for key:%s value:%v kind:%v)", key, data, reflect.TypeOf(data).Kind())
}
// ToStringMap creates a map[string]interface{} from a Parser.
func (l *Conf) ToStringMap() map[string]interface{} {
// ToStringMap creates a map[string]any from a Parser.
func (l *Conf) ToStringMap() map[string]any {
return maps.Unflatten(l.k.All(), KeyDelimiter)
}
@ -155,7 +155,7 @@ func (l *Conf) ToStringMap() map[string]interface{} {
// uniqueness of component IDs (see mapKeyStringToMapKeyTextUnmarshalerHookFunc).
// Decodes time.Duration from strings. Allows custom unmarshaling for structs implementing
// encoding.TextUnmarshaler. Allows custom unmarshaling for structs implementing confmap.Unmarshaler.
func decodeConfig(m *Conf, result interface{}, errorUnused bool) error {
func decodeConfig(m *Conf, result any, errorUnused bool) error {
dc := &mapstructure.DecoderConfig{
ErrorUnused: errorUnused,
Result: result,
@ -180,7 +180,7 @@ func decodeConfig(m *Conf, result interface{}, errorUnused bool) error {
// encoderConfig returns a default encoder.EncoderConfig that includes
// an EncodeHook that handles both TextMarshaller and Marshaler
// interfaces.
func encoderConfig(rawVal interface{}) *encoder.EncoderConfig {
func encoderConfig(rawVal any) *encoder.EncoderConfig {
return &encoder.EncoderConfig{
EncodeHook: mapstructure.ComposeDecodeHookFunc(
encoder.TextMarshalerHookFunc(),
@ -205,7 +205,7 @@ func encoderConfig(rawVal interface{}) *encoder.EncoderConfig {
// we want an unmarshaled Config to be equivalent to
// Config{Thing: &SomeStruct{}} instead of Config{Thing: nil}
func expandNilStructPointersHookFunc() mapstructure.DecodeHookFuncValue {
return func(from reflect.Value, to reflect.Value) (interface{}, error) {
return func(from reflect.Value, to reflect.Value) (any, error) {
// ensure we are dealing with map to map comparison
if from.Kind() == reflect.Map && to.Kind() == reflect.Map {
toElem := to.Type().Elem()
@ -229,13 +229,13 @@ func expandNilStructPointersHookFunc() mapstructure.DecodeHookFuncValue {
}
// mapKeyStringToMapKeyTextUnmarshalerHookFunc returns a DecodeHookFuncType that checks that a conversion from
// map[string]interface{} to map[encoding.TextUnmarshaler]interface{} does not overwrite keys,
// map[string]any to map[encoding.TextUnmarshaler]any does not overwrite keys,
// when UnmarshalText produces equal elements from different strings (e.g. trims whitespaces).
//
// This is needed in combination with ComponentID, which may produce equal IDs for different strings,
// and an error needs to be returned in that case, otherwise the last equivalent ID overwrites the previous one.
func mapKeyStringToMapKeyTextUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
return func(f reflect.Type, t reflect.Type, data any) (any, error) {
if f.Kind() != reflect.Map || f.Key().Kind() != reflect.String {
return data, nil
}
@ -249,7 +249,7 @@ func mapKeyStringToMapKeyTextUnmarshalerHookFunc() mapstructure.DecodeHookFuncTy
}
m := reflect.MakeMap(reflect.MapOf(t.Key(), reflect.TypeOf(true)))
for k := range data.(map[string]interface{}) {
for k := range data.(map[string]any) {
tKey := reflect.New(t.Key())
if err := tKey.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(k)); err != nil {
return nil, err
@ -266,8 +266,8 @@ func mapKeyStringToMapKeyTextUnmarshalerHookFunc() mapstructure.DecodeHookFuncTy
// Provides a mechanism for individual structs to define their own unmarshal logic,
// by implementing the Unmarshaler interface.
func unmarshalerHookFunc(result interface{}) mapstructure.DecodeHookFuncValue {
return func(from reflect.Value, to reflect.Value) (interface{}, error) {
func unmarshalerHookFunc(result any) mapstructure.DecodeHookFuncValue {
return func(from reflect.Value, to reflect.Value) (any, error) {
if !to.CanAddr() {
return from.Interface(), nil
}
@ -283,7 +283,7 @@ func unmarshalerHookFunc(result interface{}) mapstructure.DecodeHookFuncValue {
return from.Interface(), nil
}
if _, ok = from.Interface().(map[string]interface{}); !ok {
if _, ok = from.Interface().(map[string]any); !ok {
return from.Interface(), nil
}
@ -292,7 +292,7 @@ func unmarshalerHookFunc(result interface{}) mapstructure.DecodeHookFuncValue {
unmarshaler = reflect.New(to.Type()).Interface().(Unmarshaler)
}
if err := unmarshaler.Unmarshal(NewFromStringMap(from.Interface().(map[string]interface{}))); err != nil {
if err := unmarshaler.Unmarshal(NewFromStringMap(from.Interface().(map[string]any))); err != nil {
return nil, err
}
@ -302,9 +302,9 @@ func unmarshalerHookFunc(result interface{}) mapstructure.DecodeHookFuncValue {
// marshalerHookFunc returns a DecodeHookFuncValue that checks structs that aren't
// the original to see if they implement the Marshaler interface.
func marshalerHookFunc(orig interface{}) mapstructure.DecodeHookFuncValue {
func marshalerHookFunc(orig any) mapstructure.DecodeHookFuncValue {
origType := reflect.TypeOf(orig)
return func(from reflect.Value, _ reflect.Value) (interface{}, error) {
return func(from reflect.Value, _ reflect.Value) (any, error) {
if from.Kind() != reflect.Struct {
return from.Interface(), nil
}

View File

@ -27,47 +27,47 @@ import (
)
func TestToStringMapFlatten(t *testing.T) {
conf := NewFromStringMap(map[string]interface{}{"key::embedded": int64(123)})
assert.Equal(t, map[string]interface{}{"key": map[string]interface{}{"embedded": int64(123)}}, conf.ToStringMap())
conf := NewFromStringMap(map[string]any{"key::embedded": int64(123)})
assert.Equal(t, map[string]any{"key": map[string]any{"embedded": int64(123)}}, conf.ToStringMap())
}
func TestToStringMap(t *testing.T) {
tests := []struct {
name string
fileName string
stringMap map[string]interface{}
stringMap map[string]any
}{
{
name: "Sample Collector configuration",
fileName: filepath.Join("testdata", "config.yaml"),
stringMap: map[string]interface{}{
"receivers": map[string]interface{}{
stringMap: map[string]any{
"receivers": map[string]any{
"nop": nil,
"nop/myreceiver": nil,
},
"processors": map[string]interface{}{
"processors": map[string]any{
"nop": nil,
"nop/myprocessor": nil,
},
"exporters": map[string]interface{}{
"exporters": map[string]any{
"nop": nil,
"nop/myexporter": nil,
},
"extensions": map[string]interface{}{
"extensions": map[string]any{
"nop": nil,
"nop/myextension": nil,
},
"service": map[string]interface{}{
"extensions": []interface{}{"nop"},
"pipelines": map[string]interface{}{
"traces": map[string]interface{}{
"receivers": []interface{}{"nop"},
"processors": []interface{}{"nop"},
"exporters": []interface{}{"nop"},
"service": map[string]any{
"extensions": []any{"nop"},
"pipelines": map[string]any{
"traces": map[string]any{
"receivers": []any{"nop"},
"processors": []any{"nop"},
"exporters": []any{"nop"},
},
},
},
@ -76,8 +76,8 @@ func TestToStringMap(t *testing.T) {
{
name: "Sample types",
fileName: filepath.Join("testdata", "basic_types.yaml"),
stringMap: map[string]interface{}{
"typed.options": map[string]interface{}{
stringMap: map[string]any{
"typed.options": map[string]any{
"floating.point.example": 3.14,
"integer.example": 1234,
"bool.example": false,
@ -89,13 +89,13 @@ func TestToStringMap(t *testing.T) {
{
name: "Embedded keys",
fileName: filepath.Join("testdata", "embedded_keys.yaml"),
stringMap: map[string]interface{}{
"typed": map[string]interface{}{"options": map[string]interface{}{
"floating": map[string]interface{}{"point": map[string]interface{}{"example": 3.14}},
"integer": map[string]interface{}{"example": 1234},
"bool": map[string]interface{}{"example": false},
"string": map[string]interface{}{"example": "this is a string"},
"nil": map[string]interface{}{"example": nil},
stringMap: map[string]any{
"typed": map[string]any{"options": map[string]any{
"floating": map[string]any{"point": map[string]any{"example": 3.14}},
"integer": map[string]any{"example": 1234},
"bool": map[string]any{"example": false},
"string": map[string]any{"example": "this is a string"},
"nil": map[string]any{"example": nil},
}},
},
},
@ -108,10 +108,10 @@ func TestToStringMap(t *testing.T) {
}
func TestExpandNilStructPointersHookFunc(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"boolean": nil,
"struct": nil,
"map_struct": map[string]interface{}{
"map_struct": map[string]any{
"struct": nil,
},
}
@ -128,10 +128,10 @@ func TestExpandNilStructPointersHookFunc(t *testing.T) {
}
func TestExpandNilStructPointersHookFuncDefaultNotNilConfigNil(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"boolean": nil,
"struct": nil,
"map_struct": map[string]interface{}{
"map_struct": map[string]any{
"struct": nil,
},
}
@ -155,7 +155,7 @@ func TestExpandNilStructPointersHookFuncDefaultNotNilConfigNil(t *testing.T) {
}
func TestUnmarshalWithErrorUnused(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"boolean": true,
"string": "this is a string",
}
@ -176,7 +176,7 @@ func (t TestConfig) Marshal(conf *Conf) error {
if err := conf.Marshal(t); err != nil {
return err
}
return conf.Merge(NewFromStringMap(map[string]interface{}{
return conf.Merge(NewFromStringMap(map[string]any{
"additional": "field",
}))
}
@ -209,9 +209,9 @@ type TestIDConfig struct {
}
func TestMapKeyStringToMapKeyTextUnmarshalerHookFunc(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"bool": true,
"map": map[string]interface{}{
"map": map[string]any{
"string": "this is a string",
},
}
@ -224,9 +224,9 @@ func TestMapKeyStringToMapKeyTextUnmarshalerHookFunc(t *testing.T) {
}
func TestMapKeyStringToMapKeyTextUnmarshalerHookFuncDuplicateID(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"bool": true,
"map": map[string]interface{}{
"map": map[string]any{
"string": "this is a string",
"string_": "this is another string",
},
@ -238,9 +238,9 @@ func TestMapKeyStringToMapKeyTextUnmarshalerHookFuncDuplicateID(t *testing.T) {
}
func TestMapKeyStringToMapKeyTextUnmarshalerHookFuncErrorUnmarshal(t *testing.T) {
stringMap := map[string]interface{}{
stringMap := map[string]any{
"bool": true,
"map": map[string]interface{}{
"map": map[string]any{
"error": "this is a string",
},
}
@ -260,7 +260,7 @@ func TestMarshal(t *testing.T) {
}
assert.NoError(t, conf.Marshal(cfg))
assert.Equal(t, true, conf.Get("bool"))
assert.Equal(t, map[string]interface{}{"string_": "this is a string"}, conf.Get("map"))
assert.Equal(t, map[string]any{"string_": "this is a string"}, conf.Get("map"))
}
func TestMarshalDuplicateID(t *testing.T) {
@ -308,11 +308,11 @@ func TestMarshaler(t *testing.T) {
}
// newConfFromFile creates a new Conf by reading the given file.
func newConfFromFile(t testing.TB, fileName string) map[string]interface{} {
func newConfFromFile(t testing.TB, fileName string) map[string]any {
content, err := os.ReadFile(filepath.Clean(fileName))
require.NoErrorf(t, err, "unable to read the file %v", fileName)
var data map[string]interface{}
var data map[string]any
require.NoError(t, yaml.Unmarshal(content, &data), "unable to parse yaml")
return NewFromStringMap(data).ToStringMap()
@ -345,8 +345,8 @@ func (nc *nextConfig) Unmarshal(component *Conf) error {
}
func TestUnmarshaler(t *testing.T) {
cfgMap := NewFromStringMap(map[string]interface{}{
"next": map[string]interface{}{
cfgMap := NewFromStringMap(map[string]any{
"next": map[string]any{
"string": "make sure this",
},
"another": "make sure this",
@ -359,8 +359,8 @@ func TestUnmarshaler(t *testing.T) {
}
func TestUnmarshalerKeepAlreadyInitialized(t *testing.T) {
cfgMap := NewFromStringMap(map[string]interface{}{
"next": map[string]interface{}{
cfgMap := NewFromStringMap(map[string]any{
"next": map[string]any{
"string": "make sure this",
},
"another": "make sure this",
@ -376,8 +376,8 @@ func TestUnmarshalerKeepAlreadyInitialized(t *testing.T) {
}
func TestDirectUnmarshaler(t *testing.T) {
cfgMap := NewFromStringMap(map[string]interface{}{
"next": map[string]interface{}{
cfgMap := NewFromStringMap(map[string]any{
"next": map[string]any{
"string": "make sure this",
},
"another": "make sure this",
@ -409,8 +409,8 @@ func (tc *errConfig) Unmarshal(component *Conf) error {
}
func TestUnmarshalerErr(t *testing.T) {
cfgMap := NewFromStringMap(map[string]interface{}{
"err": map[string]interface{}{
cfgMap := NewFromStringMap(map[string]any{
"err": map[string]any{
"foo": "will not unmarshal due to error",
},
})

View File

@ -33,7 +33,7 @@ func LoadConf(fileName string) (*confmap.Conf, error) {
return nil, fmt.Errorf("unable to read the file %v: %w", fileName, err)
}
var rawConf map[string]interface{}
var rawConf map[string]any
if err = yaml.Unmarshal(content, &rawConf); err != nil {
return nil, err
}

View File

@ -38,7 +38,7 @@ func TestLoadConfInvalidYAML(t *testing.T) {
func TestLoadConf(t *testing.T) {
cfg, err := LoadConf(filepath.Join("testdata", "simple.yaml"))
require.NoError(t, err)
assert.Equal(t, map[string]interface{}{"floating": 3.14}, cfg.ToStringMap())
assert.Equal(t, map[string]any{"floating": 3.14}, cfg.ToStringMap())
}
func TestValidateProviderScheme(t *testing.T) {

View File

@ -31,25 +31,25 @@ func New() confmap.Converter {
}
func (converter) Convert(_ context.Context, conf *confmap.Conf) error {
out := make(map[string]interface{})
out := make(map[string]any)
for _, k := range conf.AllKeys() {
out[k] = expandStringValues(conf.Get(k))
}
return conf.Merge(confmap.NewFromStringMap(out))
}
func expandStringValues(value interface{}) interface{} {
func expandStringValues(value any) any {
switch v := value.(type) {
case string:
return expandEnv(v)
case []interface{}:
nslice := make([]interface{}, 0, len(v))
case []any:
nslice := make([]any, 0, len(v))
for _, vint := range v {
nslice = append(nslice, expandStringValues(vint))
}
return nslice
case map[string]interface{}:
nmap := map[string]interface{}{}
case map[string]any:
nmap := map[string]any{}
for mk, mv := range v {
nmap[mk] = expandStringValues(mv)
}

View File

@ -67,21 +67,21 @@ func TestNewExpandConverter_EscapedMaps(t *testing.T) {
t.Setenv("MAP_VALUE", receiverExtraMapValue)
conf := confmap.NewFromStringMap(
map[string]interface{}{
"test_string_map": map[string]interface{}{
map[string]any{
"test_string_map": map[string]any{
"recv": "$MAP_VALUE",
},
"test_interface_map": map[interface{}]interface{}{
"test_interface_map": map[any]any{
"recv": "$MAP_VALUE",
}},
)
require.NoError(t, New().Convert(context.Background(), conf))
expectedMap := map[string]interface{}{
"test_string_map": map[string]interface{}{
expectedMap := map[string]any{
"test_string_map": map[string]any{
"recv": receiverExtraMapValue,
},
"test_interface_map": map[string]interface{}{
"test_interface_map": map[string]any{
"recv": receiverExtraMapValue,
}}
assert.Equal(t, expectedMap, conf.ToStringMap())
@ -95,8 +95,8 @@ func TestNewExpandConverter_EscapedEnvVars(t *testing.T) {
conf, err := confmaptest.LoadConf(filepath.Join("testdata", "expand-escaped-env.yaml"))
require.NoError(t, err, "Unable to get config")
expectedMap := map[string]interface{}{
"test_map": map[string]interface{}{
expectedMap := map[string]any{
"test_map": map[string]any{
// $$ -> escaped $
"recv.1": "$MAP_VALUE_1",
// $$$ -> escaped $ + substituted env var

View File

@ -64,12 +64,12 @@ func New(cfg *EncoderConfig) *Encoder {
// Encode takes the input and uses reflection to encode it to
// an interface based on the mapstructure spec.
func (e *Encoder) Encode(input interface{}) (interface{}, error) {
func (e *Encoder) Encode(input any) (any, error) {
return e.encode(reflect.ValueOf(input))
}
// encode processes the value based on the reflect.Kind.
func (e *Encoder) encode(value reflect.Value) (interface{}, error) {
func (e *Encoder) encode(value reflect.Value) (any, error) {
if value.IsValid() {
switch value.Kind() {
case reflect.Interface, reflect.Ptr:
@ -89,7 +89,7 @@ func (e *Encoder) encode(value reflect.Value) (interface{}, error) {
// encodeHook calls the EncodeHook in the EncoderConfig with the value passed in.
// This is called before processing structs and for primitive data types.
func (e *Encoder) encodeHook(value reflect.Value) (interface{}, error) {
func (e *Encoder) encodeHook(value reflect.Value) (any, error) {
if e.config != nil && e.config.EncodeHook != nil {
out, err := mapstructure.DecodeHookExec(e.config.EncodeHook, value, value)
if err != nil {
@ -102,7 +102,7 @@ func (e *Encoder) encodeHook(value reflect.Value) (interface{}, error) {
// encodeStruct encodes the struct by iterating over the fields, getting the
// mapstructure tagInfo for each exported field, and encoding the value.
func (e *Encoder) encodeStruct(value reflect.Value) (interface{}, error) {
func (e *Encoder) encodeStruct(value reflect.Value) (any, error) {
if value.Kind() != reflect.Struct {
return nil, &reflect.ValueError{
Method: "encodeStruct",
@ -119,7 +119,7 @@ func (e *Encoder) encodeStruct(value reflect.Value) (interface{}, error) {
if value.Kind() != reflect.Struct {
return e.encode(value)
}
result := make(map[string]interface{})
result := make(map[string]any)
for i := 0; i < value.NumField(); i++ {
field := value.Field(i)
if field.CanInterface() {
@ -132,7 +132,7 @@ func (e *Encoder) encodeStruct(value reflect.Value) (interface{}, error) {
return nil, fmt.Errorf("error encoding field %q: %w", info.name, err)
}
if info.squash {
if m, ok := encoded.(map[string]interface{}); ok {
if m, ok := encoded.(map[string]any); ok {
for k, v := range m {
result[k] = v
}
@ -146,14 +146,14 @@ func (e *Encoder) encodeStruct(value reflect.Value) (interface{}, error) {
}
// encodeSlice iterates over the slice and encodes each of the elements.
func (e *Encoder) encodeSlice(value reflect.Value) (interface{}, error) {
func (e *Encoder) encodeSlice(value reflect.Value) (any, error) {
if value.Kind() != reflect.Slice {
return nil, &reflect.ValueError{
Method: "encodeSlice",
Kind: value.Kind(),
}
}
result := make([]interface{}, value.Len())
result := make([]any, value.Len())
for i := 0; i < value.Len(); i++ {
var err error
if result[i], err = e.encode(value.Index(i)); err != nil {
@ -165,14 +165,14 @@ func (e *Encoder) encodeSlice(value reflect.Value) (interface{}, error) {
// encodeMap encodes a map by encoding the key and value. Returns errNonStringEncodedKey
// if the key is not encoded into a string.
func (e *Encoder) encodeMap(value reflect.Value) (interface{}, error) {
func (e *Encoder) encodeMap(value reflect.Value) (any, error) {
if value.Kind() != reflect.Map {
return nil, &reflect.ValueError{
Method: "encodeMap",
Kind: value.Kind(),
}
}
result := make(map[string]interface{})
result := make(map[string]any)
iterator := value.MapRange()
for iterator.Next() {
encoded, err := e.encode(iterator.Key())
@ -220,7 +220,7 @@ func getTagInfo(field reflect.StructField) *tagInfo {
// for the encoding.TextMarshaler interface and calls the MarshalText
// function if found.
func TextMarshalerHookFunc() mapstructure.DecodeHookFuncValue {
return func(from reflect.Value, _ reflect.Value) (interface{}, error) {
return func(from reflect.Value, _ reflect.Value) (any, error) {
marshaler, ok := from.Interface().(encoding.TextMarshaler)
if !ok {
return from.Interface(), nil

View File

@ -31,7 +31,7 @@ type TestComplexStruct struct {
Slice []TestSimpleStruct `mapstructure:"slice,omitempty"`
Pointer *TestSimpleStruct `mapstructure:"ptr"`
Map map[string]TestSimpleStruct `mapstructure:"map,omitempty"`
Remain map[string]interface{} `mapstructure:",remain"`
Remain map[string]any `mapstructure:",remain"`
Interface encoding.TextMarshaler
}
@ -63,8 +63,8 @@ func TestEncode(t *testing.T) {
EncodeHook: TextMarshalerHookFunc(),
})
testCases := map[string]struct {
input interface{}
want interface{}
input any
want any
}{
"WithString": {
input: "test",
@ -79,11 +79,11 @@ func TestEncode(t *testing.T) {
TestID("nop"),
TestID("type_"),
},
want: []interface{}{"nop_", "type_"},
want: []any{"nop_", "type_"},
},
"WithSimpleStruct": {
input: TestSimpleStruct{Value: "test", skipped: "skipped"},
want: map[string]interface{}{
want: map[string]any{
"value": "test",
},
},
@ -104,19 +104,19 @@ func TestEncode(t *testing.T) {
Pointer: &TestSimpleStruct{
Value: "pointer",
},
Remain: map[string]interface{}{
Remain: map[string]any{
"remain1": 23,
"remain2": "value",
},
Interface: TestID("value"),
},
want: map[string]interface{}{
want: map[string]any{
"value": "nested",
"slice": []interface{}{map[string]interface{}{"value": "slice"}},
"map": map[string]interface{}{
"Key": map[string]interface{}{"value": "map"},
"slice": []any{map[string]any{"value": "slice"}},
"map": map[string]any{
"Key": map[string]any{"value": "map"},
},
"ptr": map[string]interface{}{"value": "pointer"},
"ptr": map[string]any{"value": "pointer"},
"interface": "value_",
"remain1": 23,
"remain2": "value",
@ -202,7 +202,7 @@ func TestEncodeValueError(t *testing.T) {
enc := New(nil)
testValue := reflect.ValueOf("")
testCases := []struct {
encodeFn func(value reflect.Value) (interface{}, error)
encodeFn func(value reflect.Value) (any, error)
wantErr error
}{
{encodeFn: enc.encodeMap, wantErr: &reflect.ValueError{Method: "encodeMap", Kind: reflect.String}},
@ -220,10 +220,10 @@ func TestEncodeValueError(t *testing.T) {
func TestEncodeNonStringEncodedKey(t *testing.T) {
enc := New(nil)
testCase := []struct {
Test map[string]interface{}
Test map[string]any
}{
{
Test: map[string]interface{}{
Test: map[string]any{
"test": map[TestEmptyStruct]TestSimpleStruct{
{Value: "key"}: {Value: "value"},
},
@ -296,7 +296,7 @@ func TestEncodeNil(t *testing.T) {
}
func testHookFunc() mapstructure.DecodeHookFuncValue {
return func(from reflect.Value, _ reflect.Value) (interface{}, error) {
return func(from reflect.Value, _ reflect.Value) (any, error) {
if from.Kind() != reflect.Struct {
return from.Interface(), nil
}

View File

@ -86,7 +86,7 @@ type ChangeEvent struct {
// Retrieved holds the result of a call to the Retrieve method of a Provider object.
type Retrieved struct {
rawConf interface{}
rawConf any
closeFunc CloseFunc
}
@ -108,9 +108,9 @@ func WithRetrievedClose(closeFunc CloseFunc) RetrievedOption {
// NewRetrieved returns a new Retrieved instance that contains the data from the raw deserialized config.
// The rawConf can be one of the following types:
// - Primitives: int, int32, int64, float32, float64, bool, string;
// - []interface{};
// - map[string]interface{};
func NewRetrieved(rawConf interface{}, opts ...RetrievedOption) (*Retrieved, error) {
// - []any;
// - map[string]any;
func NewRetrieved(rawConf any, opts ...RetrievedOption) (*Retrieved, error) {
if err := checkRawConfType(rawConf); err != nil {
return nil, err
}
@ -126,18 +126,18 @@ func (r *Retrieved) AsConf() (*Conf, error) {
if r.rawConf == nil {
return New(), nil
}
val, ok := r.rawConf.(map[string]interface{})
val, ok := r.rawConf.(map[string]any)
if !ok {
return nil, fmt.Errorf("retrieved value (type=%T) cannot be used as a Conf", r.rawConf)
}
return NewFromStringMap(val), nil
}
// AsRaw returns the retrieved configuration parsed as an interface{} which can be one of the following types:
// AsRaw returns the retrieved configuration parsed as an any which can be one of the following types:
// - Primitives: int, int32, int64, float32, float64, bool, string;
// - []interface{} - every member follows the same rules as the given interface{};
// - map[string]interface{} - every value follows the same rules as the given interface{};
func (r *Retrieved) AsRaw() (interface{}, error) {
// - []any - every member follows the same rules as the given any;
// - map[string]any - every value follows the same rules as the given any;
func (r *Retrieved) AsRaw() (any, error) {
return r.rawConf, nil
}
@ -157,12 +157,12 @@ func (r *Retrieved) Close(ctx context.Context) error {
// CloseFunc a function equivalent to Retrieved.Close.
type CloseFunc func(context.Context) error
func checkRawConfType(rawConf interface{}) error {
func checkRawConfType(rawConf any) error {
if rawConf == nil {
return nil
}
switch rawConf.(type) {
case int, int32, int64, float32, float64, bool, string, []interface{}, map[string]interface{}:
case int, int32, int64, float32, float64, bool, string, []any, map[string]any:
return nil
default:
return fmt.Errorf("unsupported type=%T for retrieved config", rawConf)

View File

@ -71,7 +71,7 @@ func TestEnv(t *testing.T) {
require.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
expectedMap := confmap.NewFromStringMap(map[string]any{
"processors::batch": nil,
"exporters::otlp::endpoint": "localhost:4317",
})

View File

@ -71,7 +71,7 @@ func TestRelativePath(t *testing.T) {
require.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
expectedMap := confmap.NewFromStringMap(map[string]any{
"processors::batch": nil,
"exporters::otlp::endpoint": "localhost:4317",
})
@ -85,7 +85,7 @@ func TestAbsolutePath(t *testing.T) {
require.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
expectedMap := confmap.NewFromStringMap(map[string]interface{}{
expectedMap := confmap.NewFromStringMap(map[string]any{
"processors::batch": nil,
"exporters::otlp::endpoint": "localhost:4317",
})

View File

@ -24,7 +24,7 @@ import (
// * yamlBytes the yaml bytes that will be deserialized.
// * opts specifies options associated with this Retrieved value, such as CloseFunc.
func NewRetrievedFromYAML(yamlBytes []byte, opts ...confmap.RetrievedOption) (*confmap.Retrieved, error) {
var rawConf interface{}
var rawConf any
if err := yaml.Unmarshal(yamlBytes, &rawConf); err != nil {
return nil, err
}

View File

@ -47,9 +47,9 @@ func TestOneValue(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
"batch": map[string]interface{}{
assert.Equal(t, map[string]any{
"processors": map[string]any{
"batch": map[string]any{
"timeout": "2s",
},
},
@ -63,9 +63,9 @@ func TestNamedComponent(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
"batch/foo": map[string]interface{}{
assert.Equal(t, map[string]any{
"processors": map[string]any{
"batch/foo": map[string]any{
"timeout": "3s",
},
},
@ -79,12 +79,12 @@ func TestMapEntry(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
"batch/foo": map[string]interface{}{
assert.Equal(t, map[string]any{
"processors": map[string]any{
"batch/foo": map[string]any{
"timeout": "3s",
},
"batch": map[string]interface{}{
"batch": map[string]any{
"timeout": "2s",
},
},
@ -98,9 +98,9 @@ func TestArrayEntry(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"service": map[string]interface{}{
"extensions": []interface{}{
assert.Equal(t, map[string]any{
"service": map[string]any{
"extensions": []any{
"zpages",
"zpages/foo",
},
@ -115,12 +115,12 @@ func TestNewLine(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{
"processors": map[string]interface{}{
"batch/foo": map[string]interface{}{
assert.Equal(t, map[string]any{
"processors": map[string]any{
"batch/foo": map[string]any{
"timeout": "3s",
},
"batch": map[string]interface{}{
"batch": map[string]any{
"timeout": "2s",
},
},
@ -134,6 +134,6 @@ func TestDotSeparator(t *testing.T) {
assert.NoError(t, err)
retMap, err := ret.AsConf()
assert.NoError(t, err)
assert.Equal(t, map[string]interface{}{"processors.batch.timeout": "4s"}, retMap.ToStringMap())
assert.Equal(t, map[string]any{"processors.batch.timeout": "4s"}, retMap.ToStringMap())
assert.NoError(t, sp.Shutdown(context.Background()))
}

View File

@ -158,7 +158,7 @@ func (mr *Resolver) Resolve(ctx context.Context) (*Conf, error) {
}
if expandEnabledGauge.IsEnabled() {
cfgMap := make(map[string]interface{})
cfgMap := make(map[string]any)
for _, k := range retMap.AllKeys() {
val, err := mr.expandValueRecursively(ctx, retMap.Get(k))
if err != nil {
@ -217,7 +217,7 @@ func (mr *Resolver) closeIfNeeded(ctx context.Context) error {
return err
}
func (mr *Resolver) expandValueRecursively(ctx context.Context, value interface{}) (interface{}, error) {
func (mr *Resolver) expandValueRecursively(ctx context.Context, value any) (any, error) {
for i := 0; i < 100; i++ {
val, changed, err := mr.expandValue(ctx, value)
if err != nil {
@ -231,7 +231,7 @@ func (mr *Resolver) expandValueRecursively(ctx context.Context, value interface{
return nil, errTooManyRecursiveExpansions
}
func (mr *Resolver) expandValue(ctx context.Context, value interface{}) (interface{}, bool, error) {
func (mr *Resolver) expandValue(ctx context.Context, value any) (any, bool, error) {
switch v := value.(type) {
case string:
// If it doesn't have the format "${scheme:opaque}" no need to expand.
@ -254,8 +254,8 @@ func (mr *Resolver) expandValue(ctx context.Context, value interface{}) (interfa
mr.closers = append(mr.closers, ret.Close)
val, err := ret.AsRaw()
return val, true, err
case []interface{}:
nslice := make([]interface{}, 0, len(v))
case []any:
nslice := make([]any, 0, len(v))
nchanged := false
for _, vint := range v {
val, changed, err := mr.expandValue(ctx, vint)
@ -266,8 +266,8 @@ func (mr *Resolver) expandValue(ctx context.Context, value interface{}) (interfa
nchanged = nchanged || changed
}
return nslice, nchanged, nil
case map[string]interface{}:
nmap := map[string]interface{}{}
case map[string]any:
nmap := map[string]any{}
nchanged := false
for mk, mv := range v {
val, changed, err := mr.expandValue(ctx, mv)

View File

@ -27,7 +27,7 @@ import (
type mockProvider struct {
scheme string
retM interface{}
retM any
errR error
errS error
errW error
@ -148,7 +148,7 @@ func TestResolverErrors(t *testing.T) {
locations: []string{"mock:", "err:"},
providers: []Provider{
&mockProvider{},
&mockProvider{scheme: "err", retM: map[string]interface{}{}, errW: errors.New("watch_err")},
&mockProvider{scheme: "err", retM: map[string]any{}, errW: errors.New("watch_err")},
},
expectWatchErr: true,
},
@ -157,7 +157,7 @@ func TestResolverErrors(t *testing.T) {
locations: []string{"mock:", "err:"},
providers: []Provider{
&mockProvider{},
&mockProvider{scheme: "err", retM: map[string]interface{}{}, errC: errors.New("close_err")},
&mockProvider{scheme: "err", retM: map[string]any{}, errC: errors.New("close_err")},
},
expectCloseErr: true,
},
@ -166,7 +166,7 @@ func TestResolverErrors(t *testing.T) {
locations: []string{"mock:", "err:"},
providers: []Provider{
&mockProvider{},
&mockProvider{scheme: "err", retM: map[string]interface{}{}, errS: errors.New("close_err")},
&mockProvider{scheme: "err", retM: map[string]any{}, errS: errors.New("close_err")},
},
expectShutdownErr: true,
},
@ -380,7 +380,7 @@ func TestResolverExpandEnvVars(t *testing.T) {
}
func TestResolverDoneNotExpandOldEnvVars(t *testing.T) {
expectedCfgMap := map[string]interface{}{"test.1": "${EXTRA}", "test.2": "$EXTRA", "test.3": "${EXTRA}:${EXTRA}"}
expectedCfgMap := map[string]any{"test.1": "${EXTRA}", "test.2": "$EXTRA", "test.3": "${EXTRA}:${EXTRA}"}
fileProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(expectedCfgMap)
})
@ -402,9 +402,9 @@ func TestResolverDoneNotExpandOldEnvVars(t *testing.T) {
func TestResolverExpandMapAndSliceValues(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{
"test_map": map[string]interface{}{"recv": "${test:MAP_VALUE}"},
"test_slice": []interface{}{"${test:MAP_VALUE}"}})
return NewRetrieved(map[string]any{
"test_map": map[string]any{"recv": "${test:MAP_VALUE}"},
"test_slice": []any{"${test:MAP_VALUE}"}})
})
const receiverExtraMapValue = "some map value"
@ -417,16 +417,16 @@ func TestResolverExpandMapAndSliceValues(t *testing.T) {
cfgMap, err := resolver.Resolve(context.Background())
require.NoError(t, err)
expectedMap := map[string]interface{}{
"test_map": map[string]interface{}{"recv": receiverExtraMapValue},
"test_slice": []interface{}{receiverExtraMapValue}}
expectedMap := map[string]any{
"test_map": map[string]any{"recv": receiverExtraMapValue},
"test_slice": []any{receiverExtraMapValue}}
assert.Equal(t, expectedMap, cfgMap.ToStringMap())
}
func TestResolverInfiniteExpand(t *testing.T) {
const receiverValue = "${test:VALUE}"
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{"test": receiverValue})
return NewRetrieved(map[string]any{"test": receiverValue})
})
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
@ -442,7 +442,7 @@ func TestResolverInfiniteExpand(t *testing.T) {
func TestResolverExpandSliceValueError(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{"test": []interface{}{"${test:VALUE}"}})
return NewRetrieved(map[string]any{"test": []any{"${test:VALUE}"}})
})
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
@ -458,7 +458,7 @@ func TestResolverExpandSliceValueError(t *testing.T) {
func TestResolverExpandMapValueError(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{"test": []interface{}{map[string]interface{}{"test": "${test:VALUE}"}}})
return NewRetrieved(map[string]any{"test": []any{map[string]any{"test": "${test:VALUE}"}}})
})
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
@ -475,7 +475,7 @@ func TestResolverExpandMapValueError(t *testing.T) {
func TestResolverExpandInvalidScheme(t *testing.T) {
const receiverValue = "${g_c_s:VALUE}"
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{"test": receiverValue})
return NewRetrieved(map[string]any{"test": receiverValue})
})
testProvider := newFakeProvider("g_c_s", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
@ -493,7 +493,7 @@ func TestResolverExpandInvalidScheme(t *testing.T) {
func TestResolverExpandInvalidOpaqueValue(t *testing.T) {
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
return NewRetrieved(map[string]interface{}{"test": []interface{}{map[string]interface{}{"test": "${test:$VALUE}"}}})
return NewRetrieved(map[string]any{"test": []any{map[string]any{"test": "${test:$VALUE}"}}})
})
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {

View File

@ -56,7 +56,7 @@ func (bof *batchStruct) execute(ctx context.Context) (*batchStruct, error) {
}
// set adds a Set operation to the batch
func (bof *batchStruct) set(key string, value interface{}, marshal func(interface{}) ([]byte, error)) *batchStruct {
func (bof *batchStruct) set(key string, value any, marshal func(any) ([]byte, error)) *batchStruct {
valueBytes, err := marshal(value)
if err != nil {
bof.logger.Debug("Failed marshaling item, skipping it", zap.String(zapKey, key), zap.Error(err))
@ -89,7 +89,7 @@ func (bof *batchStruct) delete(keys ...string) *batchStruct {
// getResult returns the result of a Get operation for a given key using the provided unmarshal function.
// It should be called after execute. It may return nil value
func (bof *batchStruct) getResult(key string, unmarshal func([]byte) (interface{}, error)) (interface{}, error) {
func (bof *batchStruct) getResult(key string, unmarshal func([]byte) (any, error)) (any, error) {
op := bof.getOperations[key]
if op == nil {
return nil, errKeyNotPresentInBatch
@ -161,7 +161,7 @@ func (bof *batchStruct) setItemIndexArray(key string, value []itemIndex) *batchS
return bof.set(key, value, itemIndexArrayToBytes)
}
func itemIndexToBytes(val interface{}) ([]byte, error) {
func itemIndexToBytes(val any) ([]byte, error) {
var buf bytes.Buffer
err := binary.Write(&buf, binary.LittleEndian, val)
if err != nil {
@ -170,7 +170,7 @@ func itemIndexToBytes(val interface{}) ([]byte, error) {
return buf.Bytes(), err
}
func bytesToItemIndex(b []byte) (interface{}, error) {
func bytesToItemIndex(b []byte) (any, error) {
var val itemIndex
err := binary.Read(bytes.NewReader(b), binary.LittleEndian, &val)
if err != nil {
@ -179,7 +179,7 @@ func bytesToItemIndex(b []byte) (interface{}, error) {
return val, nil
}
func itemIndexArrayToBytes(arr interface{}) ([]byte, error) {
func itemIndexArrayToBytes(arr any) ([]byte, error) {
var buf bytes.Buffer
size := 0
@ -204,7 +204,7 @@ func itemIndexArrayToBytes(arr interface{}) ([]byte, error) {
return buf.Bytes(), err
}
func bytesToItemIndexArray(b []byte) (interface{}, error) {
func bytesToItemIndexArray(b []byte) (any, error) {
var size uint32
reader := bytes.NewReader(b)
err := binary.Read(reader, binary.LittleEndian, &size)
@ -217,10 +217,10 @@ func bytesToItemIndexArray(b []byte) (interface{}, error) {
return val, err
}
func requestToBytes(req interface{}) ([]byte, error) {
func requestToBytes(req any) ([]byte, error) {
return req.(Request).Marshal()
}
func (bof *batchStruct) bytesToRequest(b []byte) (interface{}, error) {
func (bof *batchStruct) bytesToRequest(b []byte) (any, error) {
return bof.pcs.unmarshaler(b)
}

View File

@ -29,12 +29,12 @@ type dataBuffer struct {
buf bytes.Buffer
}
func (b *dataBuffer) logEntry(format string, a ...interface{}) {
func (b *dataBuffer) logEntry(format string, a ...any) {
b.buf.WriteString(fmt.Sprintf(format, a...))
b.buf.WriteString("\n")
}
func (b *dataBuffer) logAttr(attr string, value interface{}) {
func (b *dataBuffer) logAttr(attr string, value any) {
b.logEntry(" %-15s: %s", attr, value)
}

View File

@ -295,7 +295,7 @@ func generateConfig() *Config {
DisableStacktrace: true,
OutputPaths: []string{"stderr", "./output-logs"},
ErrorOutputPaths: []string{"stderr", "./error-output-logs"},
InitialFields: map[string]interface{}{"fieldKey": "filed-value"},
InitialFields: map[string]any{"fieldKey": "filed-value"},
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelNormal,

View File

@ -74,7 +74,7 @@ var configNop = &Config{
ErrorOutputPaths: []string{"stderr"},
DisableCaller: false,
DisableStacktrace: false,
InitialFields: map[string]interface{}(nil),
InitialFields: map[string]any(nil),
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelBasic,

View File

@ -33,7 +33,7 @@ func NewConfigs[F component.Factory](factories map[component.Type]F) *Configs[F]
}
func (c *Configs[F]) Unmarshal(conf *confmap.Conf) error {
rawCfgs := make(map[component.ID]map[string]interface{})
rawCfgs := make(map[component.ID]map[string]any)
if err := conf.Unmarshal(&rawCfgs, confmap.WithErrorUnused()); err != nil {
return err
}

View File

@ -69,7 +69,7 @@ func TestUnmarshal(t *testing.T) {
for _, tk := range testKinds {
t.Run(tk.kind, func(t *testing.T) {
cfgs := NewConfigs(tk.factories)
conf := confmap.NewFromStringMap(map[string]interface{}{
conf := confmap.NewFromStringMap(map[string]any{
"nop": nil,
"nop/my" + tk.kind: nil,
})
@ -94,7 +94,7 @@ func TestUnmarshalError(t *testing.T) {
}{
{
name: "invalid-type",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nop": nil,
"/custom": nil,
}),
@ -102,7 +102,7 @@ func TestUnmarshalError(t *testing.T) {
},
{
name: "invalid-name-after-slash",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nop": nil,
"nop/": nil,
}),
@ -110,14 +110,14 @@ func TestUnmarshalError(t *testing.T) {
},
{
name: "unknown-type",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nosuch" + tk.kind: nil,
}),
expectedError: "unknown type: \"nosuch" + tk.kind + "\"",
},
{
name: "duplicate",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nop /my" + tk.kind + " ": nil,
" nop/ my" + tk.kind: nil,
}),
@ -125,8 +125,8 @@ func TestUnmarshalError(t *testing.T) {
},
{
name: "invalid-section",
conf: confmap.NewFromStringMap(map[string]interface{}{
"nop": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nop": map[string]any{
"unknown_section": tk.kind,
},
}),
@ -134,7 +134,7 @@ func TestUnmarshalError(t *testing.T) {
},
{
name: "invalid-sub-config",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"nop": "tests",
}),
expectedError: "'[nop]' expected a map, got 'string'",

View File

@ -63,7 +63,7 @@ func unmarshal(v *confmap.Conf, factories Factories) (*configSettings, error) {
ErrorOutputPaths: []string{"stderr"},
DisableCaller: false,
DisableStacktrace: false,
InitialFields: map[string]interface{}(nil),
InitialFields: map[string]any(nil),
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelBasic,

View File

@ -39,7 +39,7 @@ func TestUnmarshalEmptyAllSections(t *testing.T) {
factories, err := nopFactories()
assert.NoError(t, err)
conf := confmap.NewFromStringMap(map[string]interface{}{
conf := confmap.NewFromStringMap(map[string]any{
"receivers": nil,
"processors": nil,
"exporters": nil,
@ -71,7 +71,7 @@ func TestUnmarshalUnknownTopLevel(t *testing.T) {
factories, err := nopFactories()
assert.NoError(t, err)
conf := confmap.NewFromStringMap(map[string]interface{}{
conf := confmap.NewFromStringMap(map[string]any{
"unknown_section": nil,
})
_, err = unmarshal(conf, factories)
@ -89,7 +89,7 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
}{
{
name: "duplicate-pipeline",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"traces/ pipe": nil,
"traces /pipe": nil,
}),
@ -97,15 +97,15 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
},
{
name: "invalid-pipeline-name-after-slash",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"metrics/": nil,
}),
expectError: "in \"metrics/\" id: the part after / should not be empty",
},
{
name: "invalid-pipeline-section",
conf: confmap.NewFromStringMap(map[string]interface{}{
"traces": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"traces": map[string]any{
"unknown_section": nil,
},
}),
@ -113,24 +113,24 @@ func TestPipelineConfigUnmarshalError(t *testing.T) {
},
{
name: "invalid-pipeline-sub-config",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"traces": "string",
}),
expectError: "'[traces]' expected a map, got 'string'",
},
{
name: "invalid-pipeline-type",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"/metrics": nil,
}),
expectError: "in \"/metrics\" id: the part before / should not be empty",
},
{
name: "invalid-sequence-value",
conf: confmap.NewFromStringMap(map[string]interface{}{
"traces": map[string]interface{}{
"receivers": map[string]interface{}{
"nop": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"traces": map[string]any{
"receivers": map[string]any{
"nop": map[string]any{
"some": "config",
},
},
@ -160,9 +160,9 @@ func TestServiceUnmarshalError(t *testing.T) {
}{
{
name: "invalid-logs-level",
conf: confmap.NewFromStringMap(map[string]interface{}{
"telemetry": map[string]interface{}{
"logs": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"telemetry": map[string]any{
"logs": map[string]any{
"level": "UNKNOWN",
},
},
@ -171,9 +171,9 @@ func TestServiceUnmarshalError(t *testing.T) {
},
{
name: "invalid-metrics-level",
conf: confmap.NewFromStringMap(map[string]interface{}{
"telemetry": map[string]interface{}{
"metrics": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"telemetry": map[string]any{
"metrics": map[string]any{
"level": "unknown",
},
},
@ -182,10 +182,10 @@ func TestServiceUnmarshalError(t *testing.T) {
},
{
name: "invalid-service-extensions-section",
conf: confmap.NewFromStringMap(map[string]interface{}{
"extensions": []interface{}{
map[string]interface{}{
"nop": map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"extensions": []any{
map[string]any{
"nop": map[string]any{
"some": "config",
},
},
@ -195,14 +195,14 @@ func TestServiceUnmarshalError(t *testing.T) {
},
{
name: "invalid-service-section",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"unknown_section": "string",
}),
expectError: "'' has invalid keys: unknown_section",
},
{
name: "invalid-pipelines-config",
conf: confmap.NewFromStringMap(map[string]interface{}{
conf: confmap.NewFromStringMap(map[string]any{
"pipelines": "string",
}),
expectError: "'pipelines' expected a map, got 'string'",

View File

@ -166,12 +166,12 @@ func TestNilOrigSetValue(t *testing.T) {
assert.Equal(t, []byte{1, 2, 3}, av.Bytes().AsRaw())
av = NewValueEmpty()
assert.NoError(t, av.SetEmptyMap().FromRaw(map[string]interface{}{"k": "v"}))
assert.Equal(t, map[string]interface{}{"k": "v"}, av.Map().AsRaw())
assert.NoError(t, av.SetEmptyMap().FromRaw(map[string]any{"k": "v"}))
assert.Equal(t, map[string]any{"k": "v"}, av.Map().AsRaw())
av = NewValueEmpty()
assert.NoError(t, av.SetEmptySlice().FromRaw([]interface{}{int64(1), "val"}))
assert.Equal(t, []interface{}{int64(1), "val"}, av.Slice().AsRaw())
assert.NoError(t, av.SetEmptySlice().FromRaw([]any{int64(1), "val"}))
assert.Equal(t, []any{int64(1), "val"}, av.Slice().AsRaw())
}
func TestMap(t *testing.T) {
@ -222,12 +222,12 @@ func TestMap(t *testing.T) {
func TestMapPutEmpty(t *testing.T) {
m := NewMap()
v := m.PutEmpty("k1")
assert.EqualValues(t, map[string]interface{}{
assert.EqualValues(t, map[string]any{
"k1": nil,
}, m.AsRaw())
v.SetBool(true)
assert.EqualValues(t, map[string]interface{}{
assert.EqualValues(t, map[string]any{
"k1": true,
}, m.AsRaw())
@ -241,20 +241,20 @@ func TestMapPutEmpty(t *testing.T) {
func TestMapPutEmptyMap(t *testing.T) {
m := NewMap()
childMap := m.PutEmptyMap("k1")
assert.EqualValues(t, map[string]interface{}{
"k1": map[string]interface{}{},
assert.EqualValues(t, map[string]any{
"k1": map[string]any{},
}, m.AsRaw())
childMap.PutEmptySlice("k2").AppendEmpty().SetStr("val")
assert.EqualValues(t, map[string]interface{}{
"k1": map[string]interface{}{
"k2": []interface{}{"val"},
assert.EqualValues(t, map[string]any{
"k1": map[string]any{
"k2": []any{"val"},
},
}, m.AsRaw())
childMap.PutEmptyMap("k2").PutInt("k3", 1)
assert.EqualValues(t, map[string]interface{}{
"k1": map[string]interface{}{
"k2": map[string]interface{}{"k3": int64(1)},
assert.EqualValues(t, map[string]any{
"k1": map[string]any{
"k2": map[string]any{"k3": int64(1)},
},
}, m.AsRaw())
}
@ -262,23 +262,23 @@ func TestMapPutEmptyMap(t *testing.T) {
func TestMapPutEmptySlice(t *testing.T) {
m := NewMap()
childSlice := m.PutEmptySlice("k")
assert.EqualValues(t, map[string]interface{}{
"k": []interface{}{},
assert.EqualValues(t, map[string]any{
"k": []any{},
}, m.AsRaw())
childSlice.AppendEmpty().SetDouble(1.1)
assert.EqualValues(t, map[string]interface{}{
"k": []interface{}{1.1},
assert.EqualValues(t, map[string]any{
"k": []any{1.1},
}, m.AsRaw())
m.PutEmptySlice("k")
assert.EqualValues(t, map[string]interface{}{
"k": []interface{}{},
assert.EqualValues(t, map[string]any{
"k": []any{},
}, m.AsRaw())
childSliceVal, ok := m.Get("k")
assert.True(t, ok)
childSliceVal.Slice().AppendEmpty().SetEmptySlice().AppendEmpty().SetStr("val")
assert.EqualValues(t, map[string]interface{}{
"k": []interface{}{[]interface{}{"val"}},
assert.EqualValues(t, map[string]any{
"k": []any{[]any{"val"}},
}, m.AsRaw())
}
@ -428,7 +428,7 @@ func TestMapIterationNil(t *testing.T) {
}
func TestMap_Range(t *testing.T) {
rawMap := map[string]interface{}{
rawMap := map[string]any{
"k_string": "123",
"k_int": int64(123),
"k_double": float64(1.23),
@ -456,7 +456,7 @@ func TestMap_Range(t *testing.T) {
func TestMap_FromRaw(t *testing.T) {
am := NewMap()
assert.NoError(t, am.FromRaw(map[string]interface{}{}))
assert.NoError(t, am.FromRaw(map[string]any{}))
assert.Equal(t, 0, am.Len())
am.PutEmpty("k")
assert.Equal(t, 1, am.Len())
@ -466,15 +466,15 @@ func TestMap_FromRaw(t *testing.T) {
am.PutEmpty("k")
assert.Equal(t, 1, am.Len())
assert.NoError(t, am.FromRaw(map[string]interface{}{
assert.NoError(t, am.FromRaw(map[string]any{
"k_string": "123",
"k_int": 123,
"k_double": 1.23,
"k_bool": true,
"k_null": nil,
"k_bytes": []byte{1, 2, 3},
"k_slice": []interface{}{1, 2.1, "val"},
"k_map": map[string]interface{}{
"k_slice": []any{1, 2.1, "val"},
"k_map": map[string]any{
"k_int": 1,
"k_string": "val",
},
@ -497,10 +497,10 @@ func TestMap_FromRaw(t *testing.T) {
assert.Equal(t, []byte{1, 2, 3}, v.Bytes().AsRaw())
v, ok = am.Get("k_slice")
assert.True(t, ok)
assert.Equal(t, []interface{}{int64(1), 2.1, "val"}, v.Slice().AsRaw())
assert.Equal(t, []any{int64(1), 2.1, "val"}, v.Slice().AsRaw())
v, ok = am.Get("k_map")
assert.True(t, ok)
assert.Equal(t, map[string]interface{}{
assert.Equal(t, map[string]any{
"k_int": int64(1),
"k_string": "val",
}, v.Map().AsRaw())
@ -609,37 +609,37 @@ func TestMap_RemoveIf(t *testing.T) {
func generateTestEmptyMap(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": map[string]interface{}(nil)}))
assert.NoError(t, m.FromRaw(map[string]any{"k": map[string]any(nil)}))
return m
}
func generateTestEmptySlice(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": []interface{}(nil)}))
assert.NoError(t, m.FromRaw(map[string]any{"k": []any(nil)}))
return m
}
func generateTestIntMap(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": 123}))
assert.NoError(t, m.FromRaw(map[string]any{"k": 123}))
return m
}
func generateTestDoubleMap(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": 12.3}))
assert.NoError(t, m.FromRaw(map[string]any{"k": 12.3}))
return m
}
func generateTestBoolMap(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": true}))
assert.NoError(t, m.FromRaw(map[string]any{"k": true}))
return m
}
func generateTestBytesMap(t *testing.T) Map {
m := NewMap()
assert.NoError(t, m.FromRaw(map[string]interface{}{"k": []byte{1, 2, 3, 4, 5}}))
assert.NoError(t, m.FromRaw(map[string]any{"k": []byte{1, 2, 3, 4, 5}}))
return m
}
@ -780,7 +780,7 @@ func TestValueAsRaw(t *testing.T) {
tests := []struct {
name string
input Value
expected interface{}
expected any
}{
{
name: "string",
@ -810,16 +810,16 @@ func TestValueAsRaw(t *testing.T) {
{
name: "slice",
input: generateTestValueSlice(),
expected: []interface{}{"strVal", int64(7), 18.6, false, nil},
expected: []any{"strVal", int64(7), 18.6, false, nil},
},
{
name: "map",
input: generateTestValueMap(),
expected: map[string]interface{}{
"mapKey": map[string]interface{}{"keyOne": "valOne", "keyTwo": "valTwo"},
expected: map[string]any{
"mapKey": map[string]any{"keyOne": "valOne", "keyTwo": "valTwo"},
"nullKey": nil,
"strKey": "strVal",
"arrKey": []interface{}{"strOne", "strTwo"},
"arrKey": []any{"strOne", "strTwo"},
"boolKey": false,
"floatKey": 18.6,
"intKey": int64(7),
@ -835,14 +835,14 @@ func TestValueAsRaw(t *testing.T) {
}
func TestMapAsRaw(t *testing.T) {
raw := map[string]interface{}{
"array": []interface{}{false, []byte("test"), 12.9, int64(91), "another string"},
raw := map[string]any{
"array": []any{false, []byte("test"), 12.9, int64(91), "another string"},
"bool": true,
"bytes": []byte("bytes value"),
"double": 1.2,
"empty": nil,
"int": int64(900),
"map": map[string]interface{}{"str": "val"},
"map": map[string]any{"str": "val"},
"string": "string value",
}
m := NewMap()
@ -853,7 +853,7 @@ func TestMapAsRaw(t *testing.T) {
func TestNewValueFromRaw(t *testing.T) {
tests := []struct {
name string
input interface{}
input any
expected Value
}{
{
@ -942,39 +942,39 @@ func TestNewValueFromRaw(t *testing.T) {
},
{
name: "map",
input: map[string]interface{}{
input: map[string]any{
"k": "v",
},
expected: func() Value {
m := NewValueMap()
assert.NoError(t, m.Map().FromRaw(map[string]interface{}{"k": "v"}))
assert.NoError(t, m.Map().FromRaw(map[string]any{"k": "v"}))
return m
}(),
},
{
name: "empty map",
input: map[string]interface{}{},
input: map[string]any{},
expected: func() Value {
m := NewValueMap()
assert.NoError(t, m.Map().FromRaw(map[string]interface{}{}))
assert.NoError(t, m.Map().FromRaw(map[string]any{}))
return m
}(),
},
{
name: "slice",
input: []interface{}{"v1", "v2"},
input: []any{"v1", "v2"},
expected: (func() Value {
s := NewValueSlice()
assert.NoError(t, s.Slice().FromRaw([]interface{}{"v1", "v2"}))
assert.NoError(t, s.Slice().FromRaw([]any{"v1", "v2"}))
return s
})(),
},
{
name: "empty slice",
input: []interface{}{},
input: []any{},
expected: (func() Value {
s := NewValueSlice()
assert.NoError(t, s.Slice().FromRaw([]interface{}{}))
assert.NoError(t, s.Slice().FromRaw([]any{}))
return s
})(),
},

View File

@ -87,8 +87,7 @@ func TestLogsJSON(t *testing.T) {
jsonBuf, err := encoder.MarshalLogs(ld)
assert.NoError(t, err)
decoder := &JSONUnmarshaler{}
var got interface{}
got, err = decoder.UnmarshalLogs(jsonBuf)
got, err := decoder.UnmarshalLogs(jsonBuf)
assert.NoError(t, err)
assert.EqualValues(t, ld, got)
}

View File

@ -43,8 +43,7 @@ func TestMetricsJSON(t *testing.T) {
assert.NoError(t, err)
decoder := &JSONUnmarshaler{}
var got interface{}
got, err = decoder.UnmarshalMetrics(jsonBuf)
got, err := decoder.UnmarshalMetrics(jsonBuf)
assert.NoError(t, err)
assert.EqualValues(t, metricsOTLP, got)

View File

@ -251,7 +251,7 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
assert.EqualValues(t, 1, resourceMetrics.Len())
resourceMetric := resourceMetrics.At(0)
assert.EqualValues(t, map[string]interface{}{
assert.EqualValues(t, map[string]any{
"string": "string-resource",
}, resourceMetric.Resource().Attributes().AsRaw())
metrics := resourceMetric.ScopeMetrics().At(0).Metrics()
@ -269,12 +269,12 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
assert.EqualValues(t, startTime, gaugeDataPoints.At(0).StartTimestamp())
assert.EqualValues(t, endTime, gaugeDataPoints.At(0).Timestamp())
assert.EqualValues(t, 123.1, gaugeDataPoints.At(0).DoubleValue())
assert.EqualValues(t, map[string]interface{}{"key0": "value0"}, gaugeDataPoints.At(0).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key0": "value0"}, gaugeDataPoints.At(0).Attributes().AsRaw())
// Second point
assert.EqualValues(t, startTime, gaugeDataPoints.At(1).StartTimestamp())
assert.EqualValues(t, endTime, gaugeDataPoints.At(1).Timestamp())
assert.EqualValues(t, 456.1, gaugeDataPoints.At(1).DoubleValue())
assert.EqualValues(t, map[string]interface{}{"key1": "value1"}, gaugeDataPoints.At(1).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key1": "value1"}, gaugeDataPoints.At(1).Attributes().AsRaw())
// Check double metric
metricDouble := metrics.At(1)
@ -290,12 +290,12 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
assert.EqualValues(t, startTime, sumDataPoints.At(0).StartTimestamp())
assert.EqualValues(t, endTime, sumDataPoints.At(0).Timestamp())
assert.EqualValues(t, 123.1, sumDataPoints.At(0).DoubleValue())
assert.EqualValues(t, map[string]interface{}{"key0": "value0"}, sumDataPoints.At(0).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key0": "value0"}, sumDataPoints.At(0).Attributes().AsRaw())
// Second point
assert.EqualValues(t, startTime, sumDataPoints.At(1).StartTimestamp())
assert.EqualValues(t, endTime, sumDataPoints.At(1).Timestamp())
assert.EqualValues(t, 456.1, sumDataPoints.At(1).DoubleValue())
assert.EqualValues(t, map[string]interface{}{"key1": "value1"}, sumDataPoints.At(1).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key1": "value1"}, sumDataPoints.At(1).Attributes().AsRaw())
// Check histogram metric
metricHistogram := metrics.At(2)
@ -311,13 +311,13 @@ func TestOtlpToInternalReadOnly(t *testing.T) {
assert.EqualValues(t, startTime, histogramDataPoints.At(0).StartTimestamp())
assert.EqualValues(t, endTime, histogramDataPoints.At(0).Timestamp())
assert.EqualValues(t, []float64{1, 2}, histogramDataPoints.At(0).ExplicitBounds().AsRaw())
assert.EqualValues(t, map[string]interface{}{"key0": "value0"}, histogramDataPoints.At(0).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key0": "value0"}, histogramDataPoints.At(0).Attributes().AsRaw())
assert.EqualValues(t, []uint64{10, 15, 1}, histogramDataPoints.At(0).BucketCounts().AsRaw())
// Second point
assert.EqualValues(t, startTime, histogramDataPoints.At(1).StartTimestamp())
assert.EqualValues(t, endTime, histogramDataPoints.At(1).Timestamp())
assert.EqualValues(t, []float64{1}, histogramDataPoints.At(1).ExplicitBounds().AsRaw())
assert.EqualValues(t, map[string]interface{}{"key1": "value1"}, histogramDataPoints.At(1).Attributes().AsRaw())
assert.EqualValues(t, map[string]any{"key1": "value1"}, histogramDataPoints.At(1).Attributes().AsRaw())
assert.EqualValues(t, []uint64{10, 1}, histogramDataPoints.At(1).BucketCounts().AsRaw())
}
@ -352,7 +352,7 @@ func TestOtlpToFromInternalReadOnly(t *testing.T) {
}
func TestOtlpToFromInternalGaugeMutating(t *testing.T) {
newAttributes := map[string]interface{}{"k": "v"}
newAttributes := map[string]any{"k": "v"}
md := newMetrics(&otlpcollectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{
@ -434,7 +434,7 @@ func TestOtlpToFromInternalGaugeMutating(t *testing.T) {
}
func TestOtlpToFromInternalSumMutating(t *testing.T) {
newAttributes := map[string]interface{}{"k": "v"}
newAttributes := map[string]any{"k": "v"}
md := newMetrics(&otlpcollectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{
@ -518,7 +518,7 @@ func TestOtlpToFromInternalSumMutating(t *testing.T) {
}
func TestOtlpToFromInternalHistogramMutating(t *testing.T) {
newAttributes := map[string]interface{}{"k": "v"}
newAttributes := map[string]any{"k": "v"}
md := newMetrics(&otlpcollectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{
@ -601,7 +601,7 @@ func TestOtlpToFromInternalHistogramMutating(t *testing.T) {
}
func TestOtlpToFromInternalExponentialHistogramMutating(t *testing.T) {
newAttributes := map[string]interface{}{"k": "v"}
newAttributes := map[string]any{"k": "v"}
md := newMetrics(&otlpcollectormetrics.ExportMetricsServiceRequest{
ResourceMetrics: []*otlpmetrics.ResourceMetrics{

View File

@ -42,8 +42,7 @@ func TestTracesJSON(t *testing.T) {
assert.NoError(t, err)
decoder := &JSONUnmarshaler{}
var got interface{}
got, err = decoder.UnmarshalTraces(jsonBuf)
got, err := decoder.UnmarshalTraces(jsonBuf)
assert.NoError(t, err)
assert.EqualValues(t, tracesOTLP, got)

View File

@ -47,7 +47,7 @@ type batchProcessor struct {
sendBatchSize int
sendBatchMaxSize int
newItem chan interface{}
newItem chan any
batch batch
shutdownC chan struct{}
@ -64,7 +64,7 @@ type batch interface {
itemCount() int
// add item to the current batch
add(item interface{})
add(item any)
}
var _ consumer.Traces = (*batchProcessor)(nil)
@ -85,7 +85,7 @@ func newBatchProcessor(set processor.CreateSettings, cfg *Config, batch batch, u
sendBatchSize: int(cfg.SendBatchSize),
sendBatchMaxSize: int(cfg.SendBatchMaxSize),
timeout: cfg.Timeout,
newItem: make(chan interface{}, runtime.NumCPU()),
newItem: make(chan any, runtime.NumCPU()),
batch: batch,
shutdownC: make(chan struct{}, 1),
}, nil
@ -147,7 +147,7 @@ func (bp *batchProcessor) startProcessingCycle() {
}
}
func (bp *batchProcessor) processItem(item interface{}) {
func (bp *batchProcessor) processItem(item any) {
bp.batch.add(item)
sent := false
for bp.batch.itemCount() >= bp.sendBatchSize {
@ -226,7 +226,7 @@ func newBatchTraces(nextConsumer consumer.Traces) *batchTraces {
}
// add updates current batchTraces by adding new TraceData object
func (bt *batchTraces) add(item interface{}) {
func (bt *batchTraces) add(item any) {
td := item.(ptrace.Traces)
newSpanCount := td.SpanCount()
if newSpanCount == 0 {
@ -296,7 +296,7 @@ func (bm *batchMetrics) itemCount() int {
return bm.dataPointCount
}
func (bm *batchMetrics) add(item interface{}) {
func (bm *batchMetrics) add(item any) {
md := item.(pmetric.Metrics)
newDataPointCount := md.DataPointCount()
@ -342,7 +342,7 @@ func (bl *batchLogs) itemCount() int {
return bl.logCount
}
func (bl *batchLogs) add(item interface{}) {
func (bl *batchLogs) add(item any) {
ld := item.(plog.Logs)
newLogsCount := ld.LogRecordCount()

View File

@ -128,7 +128,7 @@ func generateConfig() *Config {
DisableStacktrace: true,
OutputPaths: []string{"stderr", "./output-logs"},
ErrorOutputPaths: []string{"stderr", "./error-output-logs"},
InitialFields: map[string]interface{}{"fieldKey": "filed-value"},
InitialFields: map[string]any{"fieldKey": "filed-value"},
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelNormal,

View File

@ -429,7 +429,7 @@ func newNopConfig() Config {
ErrorOutputPaths: []string{"stderr"},
DisableCaller: false,
DisableStacktrace: false,
InitialFields: map[string]interface{}(nil),
InitialFields: map[string]any(nil),
},
Metrics: telemetry.MetricsConfig{
Level: configtelemetry.LevelBasic,

View File

@ -93,7 +93,7 @@ type LogsConfig struct {
// foo: "bar"
//
// By default, there is no initial field.
InitialFields map[string]interface{} `mapstructure:"initial_fields"`
InitialFields map[string]any `mapstructure:"initial_fields"`
}
// LogsSamplingConfig sets a sampling strategy for the logger. Sampling caps the