Skip to content

Commit

Permalink
use 'any' instead of 'interface{}'
Browse files Browse the repository at this point in the history
  • Loading branch information
jranson committed Aug 15, 2024
1 parent fc259db commit 903e29c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/backends/influxdb/model/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func writeEpochTime(w io.Writer, epoch epoch.Epoch, m int64) {
w.Write([]byte(strconv.FormatInt(int64(epoch)/m, 10)))
}

func writeValue(w io.Writer, v interface{}, nilVal string) {
func writeValue(w io.Writer, v any, nilVal string) {
if v == nil {
w.Write([]byte(nilVal))
}
Expand All @@ -91,7 +91,7 @@ func writeValue(w io.Writer, v interface{}, nilVal string) {
}
}

func writeCSVValue(w io.Writer, v interface{}, nilVal string) {
func writeCSVValue(w io.Writer, v any, nilVal string) {
if v == nil {
w.Write([]byte(nilVal))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/backends/influxdb/model/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestWriteEpochTime(t *testing.T) {
func TestWriteValue(t *testing.T) {

tests := []struct {
val interface{}
val any
nilVal string
expectedErr error
expectedVal string
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestWriteValue(t *testing.T) {
func TestWriteCSVValue(t *testing.T) {

tests := []struct {
val interface{}
val any
nilVal string
expectedErr error
expectedVal string
Expand Down
6 changes: 3 additions & 3 deletions pkg/backends/irondb/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ func (se *SeriesEnvelope) SetVolatileExtents(e timeseries.ExtentList) {
type DataPoint struct {
Time time.Time
Step uint32
Value interface{}
Value any
}

// MarshalJSON encodes a data point value into a JSON byte slice.
func (dp *DataPoint) MarshalJSON() ([]byte, error) {
v := []interface{}{}
v := []any{}
tn := float64(0)
fv, err := strconv.ParseFloat(common.FormatTimestamp(dp.Time, true), 64)
if err == nil {
Expand All @@ -139,7 +139,7 @@ func (dp *DataPoint) MarshalJSON() ([]byte, error) {

// UnmarshalJSON decodes a JSON byte slice into this data point value.
func (dp *DataPoint) UnmarshalJSON(b []byte) error {
v := []interface{}{}
v := []any{}
err := json.Unmarshal(b, &v)
if err != nil {
return err
Expand Down
20 changes: 10 additions & 10 deletions pkg/backends/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestClone(t *testing.T) {
o := New()
o.Hosts = []string{"test"}
o.CacheName = "test"
o.CompressibleTypes = map[string]interface{}{"test": nil}
o.CompressibleTypes = map[string]any{"test": nil}
o.Paths = map[string]*po.Options{"test": p}
o.NegativeCache = map[int]time.Duration{1: 1}
o.HealthCheck = &ho.Options{}
Expand Down Expand Up @@ -210,7 +210,7 @@ func TestValidate(t *testing.T) {
to *testOptions
loc *string
val string
expected interface{}
expected any
}{
{ // 0 - invalid negative cache name
to: to,
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestValidate(t *testing.T) {
tests2 := []struct {
to *testOptions
sw []intSwapper
expected interface{}
expected any
}{
{ // case 0 - MaxShardSizeMS > 0 and MaxShardSizePoints > 0 are mutually exclusive
to: to,
Expand Down Expand Up @@ -356,12 +356,12 @@ func TestSetDefaults(t *testing.T) {

backends := Lookup{o.Name: o}

_, err = SetDefaults("test", o, o.md, nil, backends, map[string]interface{}{})
_, err = SetDefaults("test", o, o.md, nil, backends, map[string]any{})
if err != nil {
t.Error(err)
}

_, err = SetDefaults("test", o, nil, nil, backends, map[string]interface{}{})
_, err = SetDefaults("test", o, nil, nil, backends, map[string]any{})
if err != ErrInvalidMetadata {
t.Error("expected invalid metadata, got", err)
}
Expand All @@ -371,13 +371,13 @@ func TestSetDefaults(t *testing.T) {
t.Error(err)
}

_, err = SetDefaults("test", o2, o2.md, nil, backends, map[string]interface{}{})
_, err = SetDefaults("test", o2, o2.md, nil, backends, map[string]any{})
if err != nil {
t.Error(err)
}

o.Paths["series"].ReqRewriterName = "invalid"
_, err = SetDefaults("test", o, o.md, nil, backends, map[string]interface{}{})
_, err = SetDefaults("test", o, o.md, nil, backends, map[string]any{})
if err == nil {
t.Error("expected error for invalid rewriter name")
}
Expand All @@ -388,13 +388,13 @@ func TestSetDefaults(t *testing.T) {
}

_, err = SetDefaults("test", o2, o2.md, map[string]rewriter.RewriteInstructions{"test": nil},
backends, map[string]interface{}{})
backends, map[string]any{})
if err != nil {
t.Error(err)
}

_, err = SetDefaults("test", o2, o2.md, map[string]rewriter.RewriteInstructions{"not-test": nil},
backends, map[string]interface{}{})
backends, map[string]any{})
if err == nil {
t.Error("expected error for invalid rewriter name")
}
Expand All @@ -405,7 +405,7 @@ func TestSetDefaults(t *testing.T) {
}

_, err = SetDefaults("test", o2, o2.md, nil,
backends, map[string]interface{}{})
backends, map[string]any{})
if err != nil {
t.Error(err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/parsing/run_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type RunState struct {
err error
ctx context.Context
nextOverride StateFn
results map[string]interface{}
results map[string]any
pos int
cnt int
}
Expand All @@ -39,7 +39,7 @@ func NewRunState(ctx context.Context, tokens token.Tokens) *RunState {
t := tokens.Compress()
rs := &RunState{
ctx: ctx,
results: make(map[string]interface{}),
results: make(map[string]any),
tokens: t,
cnt: len(t),
pos: -1,
Expand All @@ -48,18 +48,18 @@ func NewRunState(ctx context.Context, tokens token.Tokens) *RunState {
}

// SetResultsCollection places a collection of results into the results map
func (rs *RunState) SetResultsCollection(collectionName string, val interface{}) {
func (rs *RunState) SetResultsCollection(collectionName string, val any) {
rs.results[collectionName] = val
}

// GetResultsCollection retrieves a collection from the results map
func (rs *RunState) GetResultsCollection(collectionName string) (interface{}, bool) {
func (rs *RunState) GetResultsCollection(collectionName string) (any, bool) {
v, ok := rs.results[collectionName]
return v, ok
}

// Results returns the results objecxt from the RunState
func (rs *RunState) Results() map[string]interface{} {
func (rs *RunState) Results() map[string]any {
return rs.results
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/context/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (

// WithResources returns a copy of the provided context that also includes the BackendOptions,
// CachingConfig and PathConfig for the request
func WithResources(ctx context.Context, r interface{}) context.Context {
func WithResources(ctx context.Context, r any) context.Context {
if r != nil {
return context.WithValue(StartRewriterHops(ctx), resourcesKey, r)
}
return ctx
}

// Resources returns the interface reference to the Request's resources
func Resources(ctx context.Context) interface{} {
func Resources(ctx context.Context) any {
return ctx.Value(resourcesKey)
}
4 changes: 2 additions & 2 deletions pkg/proxy/engines/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func queryConcurrent(ctx context.Context, c cache.Cache, key string, cr chan<- *
qr := &queryResult{queryKey: key, d: &HTTPDocument{}}
if c.Configuration().Provider == "memory" {
mc := c.(cache.MemoryCache)
var ifc interface{}
var ifc any
ifc, qr.lookupStatus, qr.err = mc.RetrieveReference(key, true)

if qr.err != nil || (qr.lookupStatus != status.LookupStatusHit) {
Expand Down Expand Up @@ -373,7 +373,7 @@ func writeConcurrent(ctx context.Context, c cache.Cache, key string, d *HTTPDocu

// WriteCache writes an HTTPDocument to the cache
func WriteCache(ctx context.Context, c cache.Cache, key string, d *HTTPDocument,
ttl time.Duration, compressTypes map[string]interface{}, marshal timeseries.MarshalerFunc) error {
ttl time.Duration, compressTypes map[string]any, marshal timeseries.MarshalerFunc) error {

rsc := tc.Resources(ctx).(*request.Resources)

Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/request/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Resources struct {
Logger logging.Logger
IsMergeMember bool
ResponseBytes []byte
ResponseMergeFunc interface{}
ResponseMergeFunc any
TSUnmarshaler timeseries.UnmarshalerFunc
TSMarshaler timeseries.MarshalWriterFunc
TSTransformer func(timeseries.Timeseries)
Expand Down
2 changes: 1 addition & 1 deletion pkg/timeseries/timerangequery.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type TimeRangeQuery struct {
// ValueFieldDefinitions contains the definitions for Value columns in the timeseries, based on the query
ValueFieldDefinitions []FieldDefinition `msg:"vfdefs"`
// ParsedQuery is a member for the vendor-specific query object
ParsedQuery interface{} `msg:"-"`
ParsedQuery any `msg:"-"`
}

// Clone returns an exact copy of a TimeRangeQuery
Expand Down

0 comments on commit 903e29c

Please sign in to comment.