Skip to content

Commit adfa081

Browse files
chore: updates to Go 1.25 and refactors some code (#1077)
**Description** This updates to Go 1.25 and uses some new features. See https://tip.golang.org/doc/go1.25 --------- Signed-off-by: Adrian Cole <[email protected]> Signed-off-by: Takeshi Yoneda <[email protected]> Co-authored-by: Takeshi Yoneda <[email protected]>
1 parent e74bb3f commit adfa081

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+616
-294
lines changed

api/v1alpha1/ai_gateway_route_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
inferencePoolKind = "InferencePool"
2121
)
2222

23-
// GetTimeoutsWithDefaults returns the timeouts with default values applied when not specified.
23+
// GetTimeoutsOrDefault returns the timeouts with default values applied when not specified.
2424
// This ensures that AI Gateway routes have appropriate timeout defaults for AI workloads.
2525
func (r *AIGatewayRouteRule) GetTimeoutsOrDefault() *gwapiv1.HTTPRouteTimeouts {
2626
defaultTimeout := defaultRequestTimeout

cmd/aigw/docker-compose-otel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ volumes:
1010
services:
1111
# aigw-build builds the Envoy AI Gateway CLI binary, so you can use main code.
1212
aigw-build:
13-
image: golang:1.24.6
13+
image: golang:1.25
1414
container_name: aigw-build
1515
working_dir: /workspace
1616
volumes:

cmd/aigw/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ volumes:
1111
services:
1212
# aigw-build builds the Envoy AI Gateway CLI binary, so you can use main code.
1313
aigw-build:
14-
image: golang:1.24.6
14+
image: golang:1.25
1515
container_name: aigw-build
1616
working_dir: /workspace
1717
volumes:
@@ -56,7 +56,7 @@ services:
5656

5757
# chat-completion is a simple curl-based test client for sending requests to aigw.
5858
chat-completion:
59-
image: golang:1.24.6
59+
image: golang:1.25
6060
container_name: chat-completion
6161
profiles: ["test"]
6262
env_file:

cmd/aigw/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (runCtx *runCmdContext) mustClearSetOwnerReferencesAndStatusAndWriteObj(typ
320320
if err != nil {
321321
panic(err)
322322
}
323-
var raw map[string]interface{}
323+
var raw map[string]any
324324
err = yaml.Unmarshal(marshaled, &raw)
325325
if err != nil {
326326
panic(err)

cmd/extproc/mainlib/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func listen(ctx context.Context, name, network, address string) (net.Listener, e
218218

219219
// listenAddress returns the network and address for the given address flag.
220220
func listenAddress(addrFlag string) (string, string) {
221-
if strings.HasPrefix(addrFlag, "unix://") {
222-
p := strings.TrimPrefix(addrFlag, "unix://")
221+
if after, ok := strings.CutPrefix(addrFlag, "unix://"); ok {
222+
p := after
223223
_ = os.Remove(p) // Remove the socket file if it exists.
224224
return "unix", p
225225
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/envoyproxy/ai-gateway
22

3-
go 1.24.6
3+
go 1.25
44

55
replace go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0
66

internal/apischema/anthropic/anthropic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ package anthropic
88

99
// MessagesRequest represents a request to the Anthropic Messages API.
1010
// Uses a dictionary approach to handle any JSON structure flexibly.
11-
type MessagesRequest map[string]interface{}
11+
type MessagesRequest map[string]any
1212

1313
// Helper methods to extract common fields from the dictionary
14+
1415
func (m MessagesRequest) GetModel() string {
1516
if model, ok := m["model"].(string); ok {
1617
return model

internal/apischema/awsbedrock/awsbedrock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ type ToolUseBlock struct {
287287
// Name is the name the tool that the model wants to use.
288288
Name string `json:"name"`
289289
// Input is to pass to the tool in JSON format.
290-
Input map[string]interface{} `json:"input"`
290+
Input map[string]any `json:"input"`
291291
// ToolUseID is the ID for the tool request, pattern is ^[a-zA-Z0-9_-]+$.
292292
ToolUseID string `json:"toolUseId"`
293293
}

internal/apischema/openai/openai.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type ChatCompletionContentPartUserUnionParam struct {
139139
}
140140

141141
func (c *ChatCompletionContentPartUserUnionParam) UnmarshalJSON(data []byte) error {
142-
var chatContentPart map[string]interface{}
142+
var chatContentPart map[string]any
143143
if err := json.Unmarshal(data, &chatContentPart); err != nil {
144144
return err
145145
}
@@ -187,7 +187,7 @@ func (c ChatCompletionContentPartUserUnionParam) MarshalJSON() ([]byte, error) {
187187
}
188188

189189
type StringOrAssistantRoleContentUnion struct {
190-
Value interface{}
190+
Value any
191191
}
192192

193193
func (s *StringOrAssistantRoleContentUnion) UnmarshalJSON(data []byte) error {
@@ -213,7 +213,7 @@ func (s StringOrAssistantRoleContentUnion) MarshalJSON() ([]byte, error) {
213213
}
214214

215215
type StringOrArray struct {
216-
Value interface{}
216+
Value any
217217
}
218218

219219
func (s *StringOrArray) UnmarshalJSON(data []byte) error {
@@ -256,7 +256,7 @@ func (s StringOrArray) MarshalJSON() ([]byte, error) {
256256
}
257257

258258
type StringOrUserRoleContentUnion struct {
259-
Value interface{}
259+
Value any
260260
}
261261

262262
func (s *StringOrUserRoleContentUnion) UnmarshalJSON(data []byte) error {
@@ -282,12 +282,12 @@ func (s StringOrUserRoleContentUnion) MarshalJSON() ([]byte, error) {
282282
}
283283

284284
type ChatCompletionMessageParamUnion struct {
285-
Value interface{}
285+
Value any
286286
Type string
287287
}
288288

289289
func (c *ChatCompletionMessageParamUnion) UnmarshalJSON(data []byte) error {
290-
var chatMessage map[string]interface{}
290+
var chatMessage map[string]any
291291
if err := json.Unmarshal(data, &chatMessage); err != nil {
292292
return err
293293
}
@@ -502,7 +502,6 @@ type Reasoning struct {
502502
Summary *string `json:"summary,omitempty"`
503503
}
504504

505-
// ChatCompletionRequest represents a request structure for chat completion API.
506505
// ChatCompletionModality represents the output types that the model can generate.
507506
type ChatCompletionModality string
508507

@@ -704,7 +703,7 @@ type ChatCompletionRequest struct {
704703
// Stop string / array / null Defaults to null
705704
// Up to 4 sequences where the API will stop generating further tokens.
706705
// Docs: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stop
707-
Stop interface{} `json:"stop,omitempty"`
706+
Stop any `json:"stop,omitempty"`
708707

709708
// Stream: If set, partial message deltas will be sent, like in ChatGPT.
710709
// Docs: https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream
@@ -810,7 +809,7 @@ const (
810809

811810
// ChatCompletionToolChoice represents the tool choice for chat completions.
812811
// It can be either a string (none, auto, required) or a ChatCompletionNamedToolChoice object.
813-
type ChatCompletionToolChoice interface{}
812+
type ChatCompletionToolChoice any
814813

815814
// ChatCompletionNamedToolChoice specifies a tool the model should use. Use to force the model to call a specific function.
816815
type ChatCompletionNamedToolChoice struct {
@@ -1236,7 +1235,7 @@ type Embedding struct {
12361235

12371236
// EmbeddingUnion is a union type that can handle both []float64 and string formats.
12381237
type EmbeddingUnion struct {
1239-
Value interface{}
1238+
Value any
12401239
}
12411240

12421241
// UnmarshalJSON implements json.Unmarshaler to handle both []float64 and string formats.

internal/apischema/openai/openai_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ func TestOpenAIChatCompletionMessageUnmarshal(t *testing.T) {
275275
JSONSchema: &ChatCompletionResponseFormatJSONSchema{
276276
Name: "math_response",
277277
Strict: true,
278-
Schema: map[string]interface{}{
278+
Schema: map[string]any{
279279
"additionalProperties": false,
280280
"type": "object",
281-
"properties": map[string]interface{}{
281+
"properties": map[string]any{
282282
"step": "test_step",
283283
},
284-
"required": []interface{}{"steps"},
284+
"required": []any{"steps"},
285285
},
286286
},
287287
},
@@ -310,7 +310,7 @@ func TestOpenAIChatCompletionMessageUnmarshal(t *testing.T) {
310310
},
311311
MaxCompletionTokens: ptr.To[int64](1024),
312312
ParallelToolCalls: ptr.To(true),
313-
Stop: []interface{}{"\n", "stop"},
313+
Stop: []any{"\n", "stop"},
314314
ServiceTier: ptr.To("flex"),
315315
},
316316
},
@@ -1232,7 +1232,7 @@ func TestEmbeddingUnionUnmarshal(t *testing.T) {
12321232
tests := []struct {
12331233
name string
12341234
input string
1235-
want interface{}
1235+
want any
12361236
wantErr bool
12371237
}{
12381238
{

0 commit comments

Comments
 (0)