gerrit: switch to use std context package, require Go 1.7+

This ends support for Go 1.6.

Change-Id: If7765a15add556a5a7a881b24b1a38d96ff10841
Reviewed-on: https://go-review.googlesource.com/40938
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick 2017-04-18 03:12:13 +00:00
Родитель 481d0dc16f
Коммит bce074b887
6 изменённых файлов: 5 добавлений и 42 удалений

Просмотреть файл

@ -8,6 +8,7 @@
package main
import (
"context"
"encoding/json"
"io/ioutil"
"log"
@ -17,7 +18,6 @@ import (
"time"
"golang.org/x/build/gerrit"
"golang.org/x/net/context"
)
func main() {

Просмотреть файл

@ -5,10 +5,10 @@
package gerrit_test
import (
"context"
"fmt"
"golang.org/x/build/gerrit"
"golang.org/x/net/context"
)
func Example() {

Просмотреть файл

@ -11,6 +11,7 @@ package gerrit
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@ -22,8 +23,6 @@ import (
"strconv"
"strings"
"time"
"golang.org/x/net/context"
)
// Client is a Gerrit client.
@ -133,7 +132,7 @@ func (c *Client) do(ctx context.Context, dst interface{}, method, path string, o
req.Header.Set("Content-Type", contentType)
}
c.auth.setAuth(c, req)
res, err := c.httpClient().Do(withContext(req, ctx))
res, err := c.httpClient().Do(req.WithContext(ctx))
if err != nil {
return err
}

Просмотреть файл

@ -1,17 +0,0 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.7
package gerrit
import (
"net/http"
"golang.org/x/net/context"
)
func withContext(r *http.Request, ctx context.Context) *http.Request {
return r.WithContext(ctx)
}

Просмотреть файл

@ -1,18 +0,0 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.7
package gerrit
import (
"net/http"
"golang.org/x/net/context"
)
func withContext(r *http.Request, ctx context.Context) *http.Request {
r.Cancel = ctx.Done()
return r
}

Просмотреть файл

@ -5,13 +5,12 @@
package gerrit
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"time"
"golang.org/x/net/context"
)
// taken from https://go-review.googlesource.com/projects/go