From baee6a4c8e85c471076778521a60cc23ade36f74 Mon Sep 17 00:00:00 2001 From: jwierzbo Date: Thu, 14 Nov 2024 21:40:40 +0100 Subject: [PATCH] OAS-10311 Remove deprecated context functions (#639) --- v2/CHANGELOG.md | 1 + v2/connection/call.go | 2 -- v2/connection/context.go | 24 ------------------------ v2/connection/modifiers.go | 36 ------------------------------------ 4 files changed, 1 insertion(+), 62 deletions(-) diff --git a/v2/CHANGELOG.md b/v2/CHANGELOG.md index 17a18d31..7fcfe437 100644 --- a/v2/CHANGELOG.md +++ b/v2/CHANGELOG.md @@ -5,6 +5,7 @@ - Connection configuration helper - Adjust Cursor options - Switch to Go 1.22.8 +- Remove deprecated context functions ## [2.1.1](https://github.com/arangodb/go-driver/tree/v2.1.1) (2024-09-27) - Improve backup tests stability diff --git a/v2/connection/call.go b/v2/connection/call.go index 5bcd5762..e973c49d 100644 --- a/v2/connection/call.go +++ b/v2/connection/call.go @@ -39,7 +39,6 @@ func CallWithChecks(ctx context.Context, c Connection, method, url string, outpu return nil, err } - modifiers = append(modifiers, applyGlobalSettings(ctx)) modifiers = append(modifiers, applyArangoDBConfiguration(c.GetConfiguration(), ctx)) for _, modifier := range modifiers { @@ -60,7 +59,6 @@ func CallStream(ctx context.Context, c Connection, method, url string, modifiers return nil, nil, err } - modifiers = append(modifiers, applyGlobalSettings(ctx)) modifiers = append(modifiers, applyArangoDBConfiguration(c.GetConfiguration(), ctx)) for _, modifier := range modifiers { diff --git a/v2/connection/context.go b/v2/connection/context.go index 846c38c4..da0301ce 100644 --- a/v2/connection/context.go +++ b/v2/connection/context.go @@ -22,16 +22,11 @@ package connection import ( "context" - "time" ) type ContextKey string const ( - keyUseQueueTimeout ContextKey = "arangodb-use-queue-timeout" - keyMaxQueueTime ContextKey = "arangodb-max-queue-time-seconds" - keyDriverFlags ContextKey = "arangodb-driver-flags" - keyAsyncRequest ContextKey = "arangodb-async-request" keyAsyncID ContextKey = "arangodb-async-id" ) @@ -45,25 +40,6 @@ func contextOrBackground(ctx context.Context) context.Context { return context.Background() } -// WithArangoQueueTimeout is used to enable Queue timeout on the server side. -// If WithArangoQueueTime is used, then its value takes precedence in other case value of ctx.Deadline will be taken -// Deprecated: use ArangoDBConfiguration.ArangoQueueTimeoutEnabled -func WithArangoQueueTimeout(parent context.Context, useQueueTimeout bool) context.Context { - return context.WithValue(contextOrBackground(parent), keyUseQueueTimeout, useQueueTimeout) -} - -// WithArangoQueueTime defines max queue timeout on the server side. -// Deprecated: use ArangoDBConfiguration.ArangoQueueTimeoutSec -func WithArangoQueueTime(parent context.Context, duration time.Duration) context.Context { - return context.WithValue(contextOrBackground(parent), keyMaxQueueTime, duration) -} - -// WithDriverFlags is used to configure additional flags for the `x-arango-driver` header. -// Deprecated: use ArangoDBConfiguration.DriverFlags -func WithDriverFlags(parent context.Context, value []string) context.Context { - return context.WithValue(contextOrBackground(parent), keyDriverFlags, value) -} - // WithAsync is used to configure a context to make an async operation - requires Connection with Async wrapper! func WithAsync(parent context.Context) context.Context { return context.WithValue(contextOrBackground(parent), keyAsyncRequest, true) diff --git a/v2/connection/modifiers.go b/v2/connection/modifiers.go index 4e419bee..0c9f0767 100644 --- a/v2/connection/modifiers.go +++ b/v2/connection/modifiers.go @@ -50,42 +50,6 @@ func WithQuery(s, value string) RequestModifier { } } -// applyGlobalSettings applies the settings configured in the context to the given request. -// Deprecated: use applyArangoDBConfiguration instead -func applyGlobalSettings(ctx context.Context) RequestModifier { - return func(r Request) error { - - // Set version header - val := fmt.Sprintf("go-driver-v2/%s", version.DriverVersion()) - if ctx != nil { - if v := ctx.Value(keyDriverFlags); v != nil { - if flags, ok := v.([]string); ok { - val = fmt.Sprintf("%s (%s)", val, strings.Join(flags, ",")) - } - } - } - r.AddHeader("x-arango-driver", val) - - // Enable Queue timeout - if ctx != nil { - if v := ctx.Value(keyUseQueueTimeout); v != nil { - if useQueueTimeout, ok := v.(bool); ok && useQueueTimeout { - if v := ctx.Value(keyMaxQueueTime); v != nil { - if timeout, ok := v.(time.Duration); ok { - r.AddHeader("x-arango-queue-time-seconds", fmt.Sprint(timeout.Seconds())) - } - } else if deadline, ok := ctx.Deadline(); ok { - timeout := deadline.Sub(time.Now()) - r.AddHeader("x-arango-queue-time-seconds", fmt.Sprint(timeout.Seconds())) - } - } - } - } - - return nil - } -} - func applyArangoDBConfiguration(config ArangoDBConfiguration, ctx context.Context) RequestModifier { return func(r Request) error { // Set version header