diff --git a/internal/module/db-sqlite.go b/internal/module/db-sqlite.go index a3dd227..b79e44e 100644 --- a/internal/module/db-sqlite.go +++ b/internal/module/db-sqlite.go @@ -31,7 +31,7 @@ func init() { Properties: map[string]*jsonschema.Schema{ "dsn": { Type: "string", - MinLength: jsonschema.Ptr(1), + MinLength: new(1), }, }, Required: []string{"dsn"}, diff --git a/internal/module/redis-client.go b/internal/module/redis-client.go index 16f46bd..887a120 100644 --- a/internal/module/redis-client.go +++ b/internal/module/redis-client.go @@ -68,7 +68,7 @@ func (rc *RedisClient) Type() string { return rc.config.Type } -func (rc *RedisClient) Printf(ctx context.Context, format string, v ...interface{}) { +func (rc *RedisClient) Printf(ctx context.Context, format string, v ...any) { msg := fmt.Sprintf(format, v...) rc.logger.Debug(msg) } diff --git a/internal/module/sip-dtmf-server.go b/internal/module/sip-dtmf-server.go index 6e8edcf..3c30ab2 100644 --- a/internal/module/sip-dtmf-server.go +++ b/internal/module/sip-dtmf-server.go @@ -78,8 +78,8 @@ func init() { "separator": { Title: "DTMF Separator", Type: "string", - MinLength: jsonschema.Ptr(1), - MaxLength: jsonschema.Ptr(1), + MinLength: new(1), + MaxLength: new(1), }, }, Required: []string{"separator"}, diff --git a/internal/module/tcp-server.go b/internal/module/tcp-server.go index a11498c..27e7e0a 100644 --- a/internal/module/tcp-server.go +++ b/internal/module/tcp-server.go @@ -8,6 +8,7 @@ import ( "log/slog" "net" "slices" + "strings" "sync" "syscall" "time" @@ -24,7 +25,7 @@ type TCPServer struct { Framer framer.Framer ctx context.Context router common.RouteIO - quit chan interface{} + quit chan any wg sync.WaitGroup connections []*net.TCPConn connectionsMu sync.RWMutex @@ -90,7 +91,7 @@ func init() { if err != nil { return nil, err } - return &TCPServer{Framer: framer, Addr: addr, config: moduleConfig, quit: make(chan interface{}), logger: CreateLogger(moduleConfig)}, nil + return &TCPServer{Framer: framer, Addr: addr, config: moduleConfig, quit: make(chan any), logger: CreateLogger(moduleConfig)}, nil }, }) } @@ -213,11 +214,9 @@ AcceptLoop: ts.logger.Debug("problem with listener", "error", err) } } else { - ts.wg.Add(1) - go func() { + ts.wg.Go(func() { ts.handleClient(conn) - ts.wg.Done() - }() + }) } } ts.wg.Done() @@ -232,20 +231,20 @@ func (ts *TCPServer) Output(ctx context.Context, payload any) error { return errors.New("net.tcp.server is only able to output bytes") } ts.connectionsMu.Lock() - errorString := "" + var errorString strings.Builder for _, connection := range ts.connections { _, err := connection.Write(payloadBytes) if err != nil { - errorString += fmt.Sprintf("%s\n", err.Error()) + errorString.WriteString(fmt.Sprintf("%s\n", err.Error())) } } ts.connectionsMu.Unlock() - if errorString == "" { + if errorString.String() == "" { return nil } - return fmt.Errorf("net.tcp.server error during output: %s", errorString) + return fmt.Errorf("net.tcp.server error during output: %s", errorString.String()) } func (ts *TCPServer) Stop() { diff --git a/internal/processor/db-query.go b/internal/processor/db-query.go index 76f01cc..e8087ca 100644 --- a/internal/processor/db-query.go +++ b/internal/processor/db-query.go @@ -68,10 +68,10 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay results := make([]map[string]any, 0) for rows.Next() { - columnValues := make([]interface{}, len(columns)) + columnValues := make([]any, len(columns)) for i := range columnValues { - columnValues[i] = new(interface{}) + columnValues[i] = new(any) } if err := rows.Scan(columnValues...); err != nil { @@ -81,7 +81,7 @@ func (dq *DbQuery) Process(ctx context.Context, wrappedPayload common.WrappedPay rowMap := make(map[string]any) for i, colName := range columns { - value := *columnValues[i].(*interface{}) + value := *columnValues[i].(*any) rowMap[colName] = value } results = append(results, rowMap) diff --git a/internal/processor/script-js.go b/internal/processor/script-js.go index 68876fb..42557ee 100644 --- a/internal/processor/script-js.go +++ b/internal/processor/script-js.go @@ -61,12 +61,12 @@ func (sj *ScriptJS) Process(ctx context.Context, wrappedPayload common.WrappedPa outputObject, ok := output.(*quickjs.Object) if ok { - var outputSlice []interface{} + var outputSlice []any err = outputObject.Into(&outputSlice) if err != nil { - var outputMap map[string]interface{} + var outputMap map[string]any err = outputObject.Into(&outputMap) if err != nil { wrappedPayload.End = true diff --git a/internal/processor/test/osc-message-create_test.go b/internal/processor/test/osc-message-create_test.go index e2cbe5d..91cda1d 100644 --- a/internal/processor/test/osc-message-create_test.go +++ b/internal/processor/test/osc-message-create_test.go @@ -59,7 +59,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and string arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{"arg1"}, + "args": []any{"arg1"}, "types": "s", }, payload: map[string]any{"Value": "value"}, @@ -69,7 +69,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and mixed args", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{"arg1", "42", "3.14"}, + "args": []any{"arg1", "42", "3.14"}, "types": "sif", }, payload: map[string]any{"Value": "value"}, @@ -86,7 +86,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and int64 arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{"42"}, + "args": []any{"42"}, "types": "h", }, payload: map[string]any{"Value": "value"}, @@ -96,7 +96,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and double arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{"42"}, + "args": []any{"42"}, "types": "d", }, payload: map[string]any{"Value": "value"}, @@ -106,7 +106,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and true arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{""}, + "args": []any{""}, "types": "T", }, payload: map[string]any{"Value": "value"}, @@ -116,7 +116,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and false arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{""}, + "args": []any{""}, "types": "F", }, payload: map[string]any{"Value": "value"}, @@ -126,7 +126,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "address with template and nil arg", params: map[string]any{ "address": "/test/{{.Payload.Value}}", - "args": []interface{}{""}, + "args": []any{""}, "types": "N", }, payload: map[string]any{"Value": "value"}, @@ -136,7 +136,7 @@ func TestGoodOSCMessageCreate(t *testing.T) { name: "blob arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"deadbeef"}, + "args": []any{"deadbeef"}, "types": "b", }, payload: "", @@ -228,7 +228,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "args without types parameter", params: map[string]any{ "address": "/test", - "args": []interface{}{"arg1"}, + "args": []any{"arg1"}, }, payload: "test", errorString: "osc.message.create types error: not found", @@ -237,7 +237,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "args and types length mismatch", params: map[string]any{ "address": "/test", - "args": []interface{}{"arg1", "arg2"}, + "args": []any{"arg1", "arg2"}, "types": "s", }, payload: "test", @@ -247,7 +247,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "non-string arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"arg1", 123}, + "args": []any{"arg1", 123}, "types": "ss", }, payload: "test", @@ -257,7 +257,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "bad arg template", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{"}, + "args": []any{"{{"}, "types": "s", }, payload: "test", @@ -267,7 +267,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "non-string types parameter", params: map[string]any{ "address": "/test", - "args": []interface{}{"arg1"}, + "args": []any{"arg1"}, "types": 123, }, payload: "test", @@ -277,7 +277,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "invalid type in types parameter", params: map[string]any{ "address": "/test", - "args": []interface{}{"arg1"}, + "args": []any{"arg1"}, "types": "x", }, payload: "test", @@ -311,7 +311,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "address template with missing field", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.missing}}"}, + "args": []any{"{{.missing}}"}, "types": "s", }, payload: "test", @@ -321,7 +321,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "wrong arg type for int arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.Payload}}"}, + "args": []any{"{{.Payload}}"}, "types": "i", }, payload: "test", @@ -331,7 +331,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "wrong arg type for float arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.Payload}}"}, + "args": []any{"{{.Payload}}"}, "types": "f", }, payload: "test", @@ -341,7 +341,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "wrong arg type for blob arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.Payload}}"}, + "args": []any{"{{.Payload}}"}, "types": "b", }, payload: "test", @@ -351,7 +351,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "wrong arg type for int64 arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.Payload}}"}, + "args": []any{"{{.Payload}}"}, "types": "h", }, payload: "test", @@ -361,7 +361,7 @@ func TestBadOSCMessageCreate(t *testing.T) { name: "wrong arg type for double arg", params: map[string]any{ "address": "/test", - "args": []interface{}{"{{.Payload}}"}, + "args": []any{"{{.Payload}}"}, "types": "d", }, payload: "test", diff --git a/internal/processor/test/script-js_test.go b/internal/processor/test/script-js_test.go index 8e5cacf..dbaf180 100644 --- a/internal/processor/test/script-js_test.go +++ b/internal/processor/test/script-js_test.go @@ -145,7 +145,7 @@ func TestGoodScriptJS(t *testing.T) { "program": "", }, payload: []byte("test"), - expected: []interface{}{float64('t'), float64('e'), float64('s'), float64('t')}, + expected: []any{float64('t'), float64('e'), float64('s'), float64('t')}, }, } diff --git a/internal/schema/modules.go b/internal/schema/modules.go index 71522fc..7e69f4c 100644 --- a/internal/schema/modules.go +++ b/internal/schema/modules.go @@ -26,7 +26,7 @@ func GetModulesSchema() *jsonschema.Schema { Properties: map[string]*jsonschema.Schema{ "id": { Type: "string", - MinLength: jsonschema.Ptr(1), + MinLength: new(1), }, "type": { Const: jsonschema.Ptr[any](mod.Type), diff --git a/internal/schema/routes.go b/internal/schema/routes.go index 048d54c..b5ef404 100644 --- a/internal/schema/routes.go +++ b/internal/schema/routes.go @@ -17,7 +17,7 @@ var RoutesConfigSchema = jsonschema.Schema{ Properties: map[string]*jsonschema.Schema{ "input": { Type: "string", - MinLength: jsonschema.Ptr(1), + MinLength: new(1), }, "processors": { Ref: "https://showbridge.io/processors.schema.json",