Skip to content

Commit

Permalink
OAS-10311 Remove deprecated context functions (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwierzbo authored Nov 14, 2024
1 parent fb2ca10 commit baee6a4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 62 deletions.
1 change: 1 addition & 0 deletions v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions v2/connection/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
24 changes: 0 additions & 24 deletions v2/connection/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
36 changes: 0 additions & 36 deletions v2/connection/modifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit baee6a4

Please sign in to comment.