Skip to content

Commit

Permalink
all: gofmt -w -r 'interface{} -> any' . (#184)
Browse files Browse the repository at this point in the history
* all: gofmt -w -r 'interface{} -> any' .

* Regenerate mock

Co-authored-by: Vadim Alekseev <[email protected]>
  • Loading branch information
sashamelentyev and vadimalekseev authored Oct 3, 2022
1 parent 67a211d commit 6716f87
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func tryGetSecret(vault secreter, field *simplejson.Json) (string, bool) {
}

// Parse holy shit! who write this function?
func Parse(ptr interface{}, values map[string]int) error {
func Parse(ptr any, values map[string]int) error {
v := reflect.ValueOf(ptr).Elem()
t := v.Type()

Expand Down Expand Up @@ -495,7 +495,7 @@ func ParseField(v reflect.Value, vField reflect.Value, tField reflect.StructFiel
return nil
}

func UnescapeMap(fields map[string]interface{}) map[string]string {
func UnescapeMap(fields map[string]any) map[string]string {
result := make(map[string]string)

for key, val := range fields {
Expand Down
24 changes: 12 additions & 12 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,50 +55,50 @@ func init() {
Instance.Infof("Logger initialized with level: %s", level)
}

func Debug(args ...interface{}) {
func Debug(args ...any) {
Instance.Debug(args...)
}

func Info(args ...interface{}) {
func Info(args ...any) {
Instance.Info(args...)
}

func Warn(args ...interface{}) {
func Warn(args ...any) {
Instance.Warn(args...)
}

func Error(args ...interface{}) {
func Error(args ...any) {
Instance.Error(args...)
}

func Panic(args ...interface{}) {
func Panic(args ...any) {
Instance.Panic(args...)
}

func Fatal(args ...interface{}) {
func Fatal(args ...any) {
Instance.Fatal(args...)
}

func Debugf(template string, args ...interface{}) {
func Debugf(template string, args ...any) {
Instance.Debugf(template, args...)
}

func Infof(template string, args ...interface{}) {
func Infof(template string, args ...any) {
Instance.Infof(template, args...)
}

func Warnf(template string, args ...interface{}) {
func Warnf(template string, args ...any) {
Instance.Warnf(template, args...)
}

func Errorf(template string, args ...interface{}) {
func Errorf(template string, args ...any) {
Instance.Errorf(template, args...)
}

func Panicf(template string, args ...interface{}) {
func Panicf(template string, args ...any) {
Instance.Panicf(template, args...)
}

func Fatalf(template string, args ...interface{}) {
func Fatalf(template string, args ...any) {
Instance.Fatalf(template, args...)
}
8 changes: 4 additions & 4 deletions offset/simple_offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type yamlValue struct {
value interface{}
value any
}

func (o *yamlValue) Load(r io.Reader) error {
Expand All @@ -30,16 +30,16 @@ func (o *yamlValue) Save(w io.Writer) error {
return nil
}

func newYAMLOffset(path string, value interface{}) *Offset {
func newYAMLOffset(path string, value any) *Offset {
res := NewOffset(path)
res.Callback = &yamlValue{value}
return res
}

func LoadYAML(path string, value interface{}) error {
func LoadYAML(path string, value any) error {
return newYAMLOffset(path, value).Load()
}

func SaveYAML(path string, value interface{}) error {
func SaveYAML(path string, value any) error {
return newYAMLOffset(path, value).Save()
}
12 changes: 6 additions & 6 deletions pipeline/action_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ func (s *sample) ready() <-chan bool {

func (s *sample) Marshal() []byte {
type Result struct {
ProcessorID int `json:"processor_id"`
EventBefore map[string]interface{} `json:"event_before"`
EventAfter map[string]interface{} `json:"event_after"`
EventStatus string `json:"event_status"`
ProcessorID int `json:"processor_id"`
EventBefore map[string]any `json:"event_before"`
EventAfter map[string]any `json:"event_after"`
EventStatus string `json:"event_status"`
}
r := Result{
ProcessorID: s.procID,
EventBefore: map[string]interface{}{},
EventAfter: map[string]interface{}{},
EventBefore: map[string]any{},
EventAfter: map[string]any{},
EventStatus: string(s.eventStatus),
}
_ = json.Unmarshal(s.eventBefore, &r.EventBefore)
Expand Down
2 changes: 1 addition & 1 deletion pipeline/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (b *Batcher) Start(ctx context.Context) {
longpanic.Go(b.heartbeat)
}

type WorkerData interface{}
type WorkerData any

func (b *Batcher) work(ctx context.Context) {
t := time.Now()
Expand Down
4 changes: 2 additions & 2 deletions pipeline/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ type OutputPluginInfo struct {
*PluginRuntimeInfo
}

type AnyPlugin interface{}
type AnyPlugin any

type AnyConfig interface{}
type AnyConfig any

type PluginFactory func() (AnyPlugin, AnyConfig)

Expand Down
2 changes: 1 addition & 1 deletion plugin/action/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It logs event to stdout. Useful for debugging.

type Plugin struct{}

type Config map[string]interface{}
type Config map[string]any

func init() {
fd.DefaultPluginRegistry.RegisterAction(&pipeline.PluginStaticInfo{
Expand Down
4 changes: 2 additions & 2 deletions plugin/action/rename/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Plugin struct {
preserveFields bool
}

type Config map[string]interface{}
type Config map[string]any

func init() {
fd.DefaultPluginRegistry.RegisterAction(&pipeline.PluginStaticInfo{
Expand All @@ -55,7 +55,7 @@ func factory() (pipeline.AnyPlugin, pipeline.AnyConfig) {

func (p *Plugin) Start(config pipeline.AnyConfig, _ *pipeline.ActionPluginParams) {
sharedConfig := *config.(*Config)
localConfig := make(map[string]interface{}, len(sharedConfig)) // clone shared config to be able to modify it
localConfig := make(map[string]any, len(sharedConfig)) // clone shared config to be able to modify it
for k, v := range sharedConfig {
localConfig[k] = v
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/action/throttle/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
type redisClient interface {
IncrBy(key string, value int64) *redis.IntCmd
Expire(key string, expiration time.Duration) *redis.BoolCmd
SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd
SetNX(key string, value any, expiration time.Duration) *redis.BoolCmd
Get(key string) *redis.StringCmd
Ping() *redis.StatusCmd
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/input/file/resetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func deleteOneOffsetByField(o *offsetDB, fieldName string, fieldVal uint64) {
logger.Panicf("can't read file, try to reset all file. Error: %s", err.Error())
}

files := make([]map[string]interface{}, 0)
files := make([]map[string]any, 0)
err = yaml.Unmarshal(f, &files)
if err != nil {
logger.Panicf("can't unmarshal file, try to reset all file. err: %s file:\n%s", err.Error(), f)
Expand Down
6 changes: 3 additions & 3 deletions plugin/input/k8s/gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func initInformer() {
}
podListWatcher := cache.NewListWatchFromClient(client.CoreV1().RESTClient(), "pods", "", selector)
_, c := cache.NewIndexerInformer(podListWatcher, &corev1.Pod{}, metaExpireDuration/4, cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
AddFunc: func(obj any) {
putMeta(obj.(*corev1.Pod))
},
UpdateFunc: func(old interface{}, obj interface{}) {
UpdateFunc: func(old any, obj any) {
putMeta(obj.(*corev1.Pod))
},
DeleteFunc: func(obj interface{}) {
DeleteFunc: func(obj any) {
},
}, cache.Indexers{})
controller = c
Expand Down
2 changes: 1 addition & 1 deletion plugin/output/postgres/mock/postgres.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions plugin/output/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
)

type PgxIface interface {
Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
Close()
}

Expand Down Expand Up @@ -319,7 +319,7 @@ func (p *Plugin) out(_ *pipeline.WorkerData, batch *pipeline.Batch) {
p.logger.Fatalf("Invalid SQL. query: %s, args: %v, err: %v", query, args, err)
}

var argsSliceInterface = make([]interface{}, len(args)+1)
var argsSliceInterface = make([]any, len(args)+1)

argsSliceInterface[0] = preferSimpleProtocol
for i := 1; i < len(args)+1; i++ {
Expand All @@ -344,7 +344,7 @@ func (p *Plugin) out(_ *pipeline.WorkerData, batch *pipeline.Batch) {
}
}

func (p *Plugin) try(query string, argsSliceInterface []interface{}) error {
func (p *Plugin) try(query string, argsSliceInterface []any) error {
ctx, cancel := context.WithTimeout(p.ctx, p.config.DBRequestTimeout_)
defer cancel()

Expand All @@ -358,8 +358,8 @@ func (p *Plugin) try(query string, argsSliceInterface []interface{}) error {
return err
}

func (p *Plugin) processEvent(event *pipeline.Event, pgFields []column, uniqueFields map[string]pgType) (fieldValues []interface{}, uniqueID string, err error) {
fieldValues = make([]interface{}, 0, len(pgFields))
func (p *Plugin) processEvent(event *pipeline.Event, pgFields []column, uniqueFields map[string]pgType) (fieldValues []any, uniqueID string, err error) {
fieldValues = make([]any, 0, len(pgFields))
uniqueID = ""

for _, field := range pgFields {
Expand Down Expand Up @@ -387,7 +387,7 @@ func (p *Plugin) processEvent(event *pipeline.Event, pgFields []column, uniqueFi
return fieldValues, uniqueID, nil
}

func (p *Plugin) addFieldToValues(field column, sNode *insaneJSON.StrictNode) (interface{}, error) {
func (p *Plugin) addFieldToValues(field column, sNode *insaneJSON.StrictNode) (any, error) {
switch field.ColType {
case pgString:
lVal, err := sNode.AsString()
Expand Down
14 changes: 7 additions & 7 deletions plugin/output/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestPrivateOut(t *testing.T) {
mockpool.EXPECT().Query(
gomock.AssignableToTypeOf(ctxMock),
"INSERT INTO table1 (str_uni_1,int_uni_1,int_1,timestamp_1) VALUES ($1,$2,$3,$4) ON CONFLICT(str_uni_1,int_uni_1) DO UPDATE SET int_1=EXCLUDED.int_1,timestamp_1=EXCLUDED.timestamp_1",
[]interface{}{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
[]any{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
).Return(&rowsForTest{}, nil).Times(1)

builder, err := NewQueryBuilder(columns, table)
Expand Down Expand Up @@ -149,12 +149,12 @@ func TestPrivateOutWithRetry(t *testing.T) {
mockpool.EXPECT().Query(
gomock.AssignableToTypeOf(ctxMock),
"INSERT INTO table1 (str_uni_1,int_1,timestamp_1) VALUES ($1,$2,$3) ON CONFLICT(str_uni_1) DO UPDATE SET int_1=EXCLUDED.int_1,timestamp_1=EXCLUDED.timestamp_1",
[]interface{}{preferSimpleProtocol, strUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
[]any{preferSimpleProtocol, strUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
).Return(&rowsForTest{}, errors.New("someError")).Times(2)
mockpool.EXPECT().Query(
gomock.AssignableToTypeOf(ctxMock),
"INSERT INTO table1 (str_uni_1,int_1,timestamp_1) VALUES ($1,$2,$3) ON CONFLICT(str_uni_1) DO UPDATE SET int_1=EXCLUDED.int_1,timestamp_1=EXCLUDED.timestamp_1",
[]interface{}{preferSimpleProtocol, strUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
[]any{preferSimpleProtocol, strUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
).Return(&rowsForTest{}, nil).Times(1)

builder, err := NewQueryBuilder(columns, table)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestPrivateOutDeduplicatedEvents(t *testing.T) {
mockpool.EXPECT().Query(
gomock.AssignableToTypeOf(ctxMock),
"INSERT INTO table1 (str_uni_1,int_uni_1,int_1,timestamp_1) VALUES ($1,$2,$3,$4) ON CONFLICT(str_uni_1,int_uni_1) DO UPDATE SET int_1=EXCLUDED.int_1,timestamp_1=EXCLUDED.timestamp_1",
[]interface{}{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
[]any{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339)},
).Return(&rowsForTest{}, nil).Times(1)

builder, err := NewQueryBuilder(columns, table)
Expand Down Expand Up @@ -465,7 +465,7 @@ func TestPrivateOutFewUniqueEventsYetWithDeduplicationEventsAnpooladEvents(t *te
mockpool.EXPECT().Query(
gomock.AssignableToTypeOf(ctxMock),
"INSERT INTO table1 (str_uni_1,int_uni_1,int_1,timestamp_1) VALUES ($1,$2,$3,$4),($5,$6,$7,$8) ON CONFLICT(str_uni_1,int_uni_1) DO UPDATE SET int_1=EXCLUDED.int_1,timestamp_1=EXCLUDED.timestamp_1",
[]interface{}{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339),
[]any{preferSimpleProtocol, strUniValue, intUniValue, intValue, time.Unix(int64(timestampValue), 0).Format(time.RFC3339),
secStrUniValue, secIntUniValue, secIntValue, time.Unix(int64(secTimestampValue), 0).Format(time.RFC3339)},
).Return(&rowsForTest{}, nil).Times(1)

Expand Down Expand Up @@ -500,6 +500,6 @@ func (r rowsForTest) Err() error { return ni
func (r rowsForTest) CommandTag() pgconn.CommandTag { return nil }
func (r rowsForTest) FieldDescriptions() []pgproto3.FieldDescription { return nil }
func (r rowsForTest) Next() bool { return false }
func (r rowsForTest) Scan(dest ...interface{}) error { return nil }
func (r rowsForTest) Values() ([]interface{}, error) { return nil, nil }
func (r rowsForTest) Scan(dest ...any) error { return nil }
func (r rowsForTest) Values() ([]any, error) { return nil, nil }
func (r rowsForTest) RawValues() [][]byte { return nil }
2 changes: 1 addition & 1 deletion test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func NewEmptyOutputPluginParams() *pipeline.OutputPluginParams {
}
}

func NewConfig(config interface{}, params map[string]int) interface{} {
func NewConfig(config any, params map[string]int) any {
err := cfg.Parse(config, params)
if err != nil {
logger.Panicf("wrong config: %s", err.Error())
Expand Down

0 comments on commit 6716f87

Please sign in to comment.