Skip to content

Commit afe03e8

Browse files
committed
Replace interface{} with any
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent 72743f2 commit afe03e8

6 files changed

Lines changed: 27 additions & 27 deletions

File tree

internal/telemetry/http.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
)
1212

1313
// createEvent creates an EventPayload struct from eventType and properties
14-
func (tc *Client) createEvent(eventName string, properties map[string]interface{}) EventPayload {
14+
func (tc *Client) createEvent(eventName string, properties map[string]any) EventPayload {
1515
osInfo, _, osLanguage := getSystemInfo()
1616

1717
// Create a new properties map that includes both user properties and system metadata
18-
allProperties := make(map[string]interface{})
18+
allProperties := make(map[string]any)
1919

2020
// Copy user-provided properties first
2121
for k, v := range properties {
@@ -71,7 +71,7 @@ func (tc *Client) sendEvent(event *EventPayload) {
7171
// Event processing (OpenTelemetry tracing handled in run.go)
7272

7373
// Log the event
74-
logArgs := []interface{}{
74+
logArgs := []any{
7575
"event", event.Event,
7676
"event_timestamp", event.EventTimestamp,
7777
"source", event.Source,
@@ -98,8 +98,8 @@ func (tc *Client) sendEvent(event *EventPayload) {
9898
// performHTTPRequest handles the actual HTTP request to the telemetry API
9999
func (tc *Client) performHTTPRequest(event *EventPayload) error {
100100
// Wrap event in records array to match MarlinRequest format
101-
requestBody := map[string]interface{}{
102-
"records": []interface{}{event},
101+
requestBody := map[string]any{
102+
"records": []any{event},
103103
}
104104

105105
// Serialize request to JSON

internal/telemetry/telemetry_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,14 @@ func TestAllEventTypes(t *testing.T) {
611611
}
612612

613613
// Verify request body structure
614-
var requestBody map[string]interface{}
614+
var requestBody map[string]any
615615
if err := json.Unmarshal(bodies[i], &requestBody); err != nil {
616616
t.Errorf("Request %d: Failed to unmarshal request body: %v", i, err)
617617
continue
618618
}
619619

620620
// Verify it has records array structure
621-
records, ok := requestBody["records"].([]interface{})
621+
records, ok := requestBody["records"].([]any)
622622
if !ok {
623623
t.Errorf("Request %d: Expected 'records' array in request body", i)
624624
continue
@@ -629,13 +629,13 @@ func TestAllEventTypes(t *testing.T) {
629629
}
630630

631631
// Verify the event structure
632-
record := records[0].(map[string]interface{})
632+
record := records[0].(map[string]any)
633633
if eventType, ok := record["event"].(string); !ok || eventType == "" {
634634
t.Errorf("Request %d: Expected non-empty event type, got %v", i, record["event"])
635635
}
636636

637637
// Verify properties exist
638-
if _, ok := record["properties"].(map[string]interface{}); !ok {
638+
if _, ok := record["properties"].(map[string]any); !ok {
639639
t.Errorf("Request %d: Expected properties object in event", i)
640640
}
641641
}
@@ -862,13 +862,13 @@ func TestHTTPRequestVerification(t *testing.T) {
862862
t.Fatal("Expected request body to be captured")
863863
}
864864

865-
var requestBody map[string]interface{}
865+
var requestBody map[string]any
866866
if err := json.Unmarshal(bodies[0], &requestBody); err != nil {
867867
t.Fatalf("Failed to unmarshal request body: %v", err)
868868
}
869869

870870
// Verify it has records array structure
871-
records, ok := requestBody["records"].([]interface{})
871+
records, ok := requestBody["records"].([]any)
872872
if !ok {
873873
t.Fatal("Expected 'records' array in request body")
874874
}
@@ -877,13 +877,13 @@ func TestHTTPRequestVerification(t *testing.T) {
877877
}
878878

879879
// Verify the event structure
880-
record := records[0].(map[string]interface{})
880+
record := records[0].(map[string]any)
881881
if record["event"] != "command" {
882882
t.Errorf("Expected event type 'command', got %v", record["event"])
883883
}
884884

885885
// Verify properties contain the command data
886-
properties, ok := record["properties"].(map[string]interface{})
886+
properties, ok := record["properties"].(map[string]any)
887887
if !ok {
888888
t.Fatal("Expected properties object in event")
889889
}

internal/telemetry/types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// StructuredEvent represents a type-safe telemetry event with structured properties
1313
type StructuredEvent interface {
1414
GetEventType() EventType
15-
ToStructuredProperties() interface{}
15+
ToStructuredProperties() any
1616
}
1717

1818
// Simplified event system - event types are now just strings in the Event.Event field
@@ -33,13 +33,13 @@ type EventPayload struct {
3333
EventTimestamp int64 `json:"event_timestamp"`
3434
Source string `json:"source"`
3535

36-
Properties map[string]interface{} `json:"properties,omitempty"`
36+
Properties map[string]any `json:"properties,omitempty"`
3737
}
3838

3939
// EventWithContext wraps an event with its context for async processing
4040
type EventWithContext struct {
4141
eventName string
42-
properties map[string]interface{}
42+
properties map[string]any
4343
}
4444

4545
// COMMAND EVENTS
@@ -64,7 +64,7 @@ func (e *CommandEvent) GetEventType() EventType {
6464
return EventTypeCommand
6565
}
6666

67-
func (e *CommandEvent) ToStructuredProperties() interface{} {
67+
func (e *CommandEvent) ToStructuredProperties() any {
6868
return CommandPayload{
6969
Action: e.Action,
7070
Args: e.Args,
@@ -101,7 +101,7 @@ func (e *ToolEvent) GetEventType() EventType {
101101
return EventTypeTool
102102
}
103103

104-
func (e *ToolEvent) ToStructuredProperties() interface{} {
104+
func (e *ToolEvent) ToStructuredProperties() any {
105105
return ToolPayload{
106106
Action: e.Action,
107107
SessionID: e.SessionID,
@@ -143,7 +143,7 @@ func (e *TokenEvent) GetEventType() EventType {
143143
return EventTypeToken
144144
}
145145

146-
func (e *TokenEvent) ToStructuredProperties() interface{} {
146+
func (e *TokenEvent) ToStructuredProperties() any {
147147
return TokenPayload{
148148
Action: e.Action,
149149
SessionID: e.SessionID,
@@ -195,7 +195,7 @@ func (e *SessionStartEvent) GetEventType() EventType {
195195
return EventTypeSession
196196
}
197197

198-
func (e *SessionStartEvent) ToStructuredProperties() interface{} {
198+
func (e *SessionStartEvent) ToStructuredProperties() any {
199199
return SessionStartPayload{
200200
Action: "start",
201201
SessionID: e.SessionID,
@@ -239,7 +239,7 @@ func (e *SessionEndEvent) GetEventType() EventType {
239239
return EventTypeSession
240240
}
241241

242-
func (e *SessionEndEvent) ToStructuredProperties() interface{} {
242+
func (e *SessionEndEvent) ToStructuredProperties() any {
243243
return SessionEndPayload{
244244
Action: "end",
245245
SessionID: e.SessionID,

internal/telemetry/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ func saveUserUUID(newUUID string) error {
108108
return os.WriteFile(uuidFile, []byte(newUUID), 0o600)
109109
}
110110

111-
// structToMap converts a struct to map[string]interface{} using JSON marshaling
111+
// structToMap converts a struct to map[string]any using JSON marshaling
112112
// This automatically handles all fields and respects JSON tags (including omitempty)
113-
func structToMap(v interface{}) (map[string]interface{}, error) {
113+
func structToMap(v any) (map[string]any, error) {
114114
data, err := json.Marshal(v)
115115
if err != nil {
116116
return nil, fmt.Errorf("failed to marshal struct: %w", err)
117117
}
118118

119-
var result map[string]interface{}
119+
var result map[string]any
120120
err = json.Unmarshal(data, &result)
121121
if err != nil {
122122
return nil, fmt.Errorf("failed to unmarshal to map: %w", err)

pkg/model/provider/anthropic/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ func convertMessages(messages []chat.Message) []anthropic.MessageParam {
225225

226226
// Create image block using raw JSON approach
227227
// Based on: https://docs.anthropic.com/en/api/messages-vision
228-
imageBlockJSON := map[string]interface{}{
228+
imageBlockJSON := map[string]any{
229229
"type": "image",
230-
"source": map[string]interface{}{
230+
"source": map[string]any{
231231
"type": "base64",
232232
"media_type": mediaType,
233233
"data": base64Data,

pkg/tools/builtin/script_shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (t *ScriptShellTool) Tools(context.Context) ([]tools.Tool, error) {
9696
}
9797

9898
func (t *ScriptShellTool) execute(ctx context.Context, toolConfig *latest.ScriptShellToolConfig, toolCall tools.ToolCall) (*tools.ToolCallResult, error) {
99-
var params map[string]interface{}
99+
var params map[string]any
100100
if err := json.Unmarshal([]byte(toolCall.Function.Arguments), &params); err != nil {
101101
return nil, fmt.Errorf("invalid arguments: %w", err)
102102
}

0 commit comments

Comments
 (0)