Skip to content

Commit

Permalink
Switch to stdlib context package (go1.8+) (#514)
Browse files Browse the repository at this point in the history
This commit switches Elastic v5 from `"golang.org/x/net/context"` to stdlib `"context"`. It also removes `ctxhttp` and uses stlib `http.Request.WithContext(...)` .

See #425
  • Loading branch information
eticzon authored and olivere committed Apr 23, 2017
1 parent 00cf81d commit 504b3df
Show file tree
Hide file tree
Showing 125 changed files with 127 additions and 252 deletions.
3 changes: 1 addition & 2 deletions bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ package elastic

import (
"bytes"
"context"
"errors"
"fmt"
"net/url"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions bulk_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package elastic

import (
"context"
"sync"
"sync/atomic"
"time"

"golang.org/x/net/context"
)

// BulkProcessorService allows to easily process bulk requests. It allows setting
Expand Down
3 changes: 1 addition & 2 deletions bulk_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
package elastic

import (
"context"
"fmt"
"math/rand"
"sync/atomic"
"testing"
"time"

"golang.org/x/net/context"
)

func TestBulkProcessorDefaults(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
"encoding/json"
"testing"

"golang.org/x/net/context"
)

func TestBulk(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions clear_scroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
"fmt"
"net/url"

"golang.org/x/net/context"
)

// ClearScrollService clears one or more scroll contexts by their ids.
Expand Down
3 changes: 1 addition & 2 deletions clear_scroll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
_ "net/http"
"testing"

"golang.org/x/net/context"
)

func TestClearScroll(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package elastic

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -16,9 +17,6 @@ import (
"strings"
"sync"
"time"

"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"
)

const (
Expand Down Expand Up @@ -1204,7 +1202,7 @@ func (c *Client) PerformRequest(ctx context.Context, method, path string, params
c.dumpRequest((*http.Request)(req))

// Get response
res, err := ctxhttp.Do(ctx, c.c, (*http.Request)(req))
res, err := c.c.Do((*http.Request)(req).WithContext(ctx))
if err == context.Canceled || err == context.DeadlineExceeded {
// Proceed, but don't mark the node as dead
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package elastic

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -15,8 +16,6 @@ import (
"strings"
"testing"
"time"

"golang.org/x/net/context"
)

func findConn(s string, slice ...*conn) (int, bool) {
Expand Down
3 changes: 1 addition & 2 deletions cluster-test/cluster-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"context"
"encoding/json"
"errors"
"flag"
Expand All @@ -17,8 +18,6 @@ import (
"sync/atomic"
"time"

"golang.org/x/net/context"

elastic "gopkg.in/olivere/elastic.v5"
)

Expand Down
3 changes: 1 addition & 2 deletions cluster_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions cluster_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
"net/url"
"testing"

"golang.org/x/net/context"
)

func TestClusterHealth(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions cluster_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions cluster_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
"net/url"
"testing"

"golang.org/x/net/context"
)

func TestClusterState(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions cluster_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions cluster_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package elastic

import (
"context"
"net/url"
"testing"

"golang.org/x/net/context"
)

func TestClusterStats(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions count.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestCountURL(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ package elastic

import (
"bytes"
"context"
"encoding/json"
"sync/atomic"
"testing"

"golang.org/x/net/context"
)

type decoder struct {
Expand Down
3 changes: 1 addition & 2 deletions delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package elastic

import (
"context"
"fmt"
"net/url"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions delete_by_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions delete_by_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestDeleteByQueryBuildURL(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions delete_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package elastic

import (
"context"
"fmt"
"net/url"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions delete_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestDeleteTemplateValidate(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestDelete(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
package elastic_test

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"reflect"
"time"

"golang.org/x/net/context"

elastic "gopkg.in/olivere/elastic.v5"
)

Expand Down
3 changes: 1 addition & 2 deletions exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/http"
"net/url"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions exists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestExists(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package elastic

import (
"context"
"fmt"
"net/url"
"strings"

"golang.org/x/net/context"

"gopkg.in/olivere/elastic.v5/uritemplates"
)

Expand Down
3 changes: 1 addition & 2 deletions explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package elastic

import (
"context"
"testing"

"golang.org/x/net/context"
)

func TestExplain(t *testing.T) {
Expand Down
Loading

0 comments on commit 504b3df

Please sign in to comment.