Skip to content

Commit 8528737

Browse files
authored
Revert "Remove Go1.6 support (#1492)"
This reverts commit c840555.
1 parent c81c59f commit 8528737

18 files changed

+413
-75
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: go
22

33
go:
4+
- 1.6.x
45
- 1.7.x
56
- 1.8.x
67
- 1.9.x

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ go get -u google.golang.org/grpc
1616
Prerequisites
1717
-------------
1818

19-
This requires Go 1.7 or later.
19+
This requires Go 1.6 or later.
2020

2121
Constraints
2222
-----------

benchmark/benchmark16_test.go

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// +build go1.6,!go1.7
2+
3+
/*
4+
*
5+
* Copyright 2017 gRPC authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
package benchmark
22+
23+
import (
24+
"os"
25+
"testing"
26+
27+
"google.golang.org/grpc"
28+
"google.golang.org/grpc/benchmark/stats"
29+
)
30+
31+
func BenchmarkClientStreamc1(b *testing.B) {
32+
grpc.EnableTracing = true
33+
runStream(b, stats.Features{"", true, 0, 0, 0, 1, 1, 1, false})
34+
}
35+
36+
func BenchmarkClientStreamc8(b *testing.B) {
37+
grpc.EnableTracing = true
38+
runStream(b, stats.Features{"", true, 0, 0, 0, 8, 1, 1, false})
39+
}
40+
41+
func BenchmarkClientStreamc64(b *testing.B) {
42+
grpc.EnableTracing = true
43+
runStream(b, stats.Features{"", true, 0, 0, 0, 64, 1, 1, false})
44+
}
45+
46+
func BenchmarkClientStreamc512(b *testing.B) {
47+
grpc.EnableTracing = true
48+
runStream(b, stats.Features{"", true, 0, 0, 0, 512, 1, 1, false})
49+
}
50+
func BenchmarkClientUnaryc1(b *testing.B) {
51+
grpc.EnableTracing = true
52+
runStream(b, stats.Features{"", true, 0, 0, 0, 1, 1, 1, false})
53+
}
54+
55+
func BenchmarkClientUnaryc8(b *testing.B) {
56+
grpc.EnableTracing = true
57+
runStream(b, stats.Features{"", true, 0, 0, 0, 8, 1, 1, false})
58+
}
59+
60+
func BenchmarkClientUnaryc64(b *testing.B) {
61+
grpc.EnableTracing = true
62+
runStream(b, stats.Features{"", true, 0, 0, 0, 64, 1, 1, false})
63+
}
64+
65+
func BenchmarkClientUnaryc512(b *testing.B) {
66+
grpc.EnableTracing = true
67+
runStream(b, stats.Features{"", true, 0, 0, 0, 512, 1, 1, false})
68+
}
69+
70+
func BenchmarkClientStreamNoTracec1(b *testing.B) {
71+
grpc.EnableTracing = false
72+
runStream(b, stats.Features{"", false, 0, 0, 0, 1, 1, 1, false})
73+
}
74+
75+
func BenchmarkClientStreamNoTracec8(b *testing.B) {
76+
grpc.EnableTracing = false
77+
runStream(b, stats.Features{"", false, 0, 0, 0, 8, 1, 1, false})
78+
}
79+
80+
func BenchmarkClientStreamNoTracec64(b *testing.B) {
81+
grpc.EnableTracing = false
82+
runStream(b, stats.Features{"", false, 0, 0, 0, 64, 1, 1, false})
83+
}
84+
85+
func BenchmarkClientStreamNoTracec512(b *testing.B) {
86+
grpc.EnableTracing = false
87+
runStream(b, stats.Features{"", false, 0, 0, 0, 512, 1, 1, false})
88+
}
89+
func BenchmarkClientUnaryNoTracec1(b *testing.B) {
90+
grpc.EnableTracing = false
91+
runStream(b, stats.Features{"", false, 0, 0, 0, 1, 1, 1, false})
92+
}
93+
94+
func BenchmarkClientUnaryNoTracec8(b *testing.B) {
95+
grpc.EnableTracing = false
96+
runStream(b, stats.Features{"", false, 0, 0, 0, 8, 1, 1, false})
97+
}
98+
99+
func BenchmarkClientUnaryNoTracec64(b *testing.B) {
100+
grpc.EnableTracing = false
101+
runStream(b, stats.Features{"", false, 0, 0, 0, 64, 1, 1, false})
102+
}
103+
104+
func BenchmarkClientUnaryNoTracec512(b *testing.B) {
105+
grpc.EnableTracing = false
106+
runStream(b, stats.Features{"", false, 0, 0, 0, 512, 1, 1, false})
107+
runStream(b, stats.Features{"", false, 0, 0, 0, 512, 1, 1, false})
108+
}
109+
110+
func TestMain(m *testing.M) {
111+
os.Exit(stats.RunTestMain(m))
112+
}
File renamed without changes.

clientconn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
378378
if cc.dopts.copts.Dialer == nil {
379379
cc.dopts.copts.Dialer = newProxyDialer(
380380
func(ctx context.Context, addr string) (net.Conn, error) {
381-
return (&net.Dialer{}).DialContext(ctx, "tcp", addr)
381+
return dialContext(ctx, "tcp", addr)
382382
},
383383
)
384384
}

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For this sample, we've already generated the server and client stubs from [hello
88
PREREQUISITES
99
-------------
1010

11-
- This requires Go 1.7 or later
11+
- This requires Go 1.5 or later
1212
- Requires that [GOPATH is set](https://golang.org/doc/code.html#GOPATH)
1313

1414
```

go16.go

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// +build go1.6,!go1.7
2+
3+
/*
4+
*
5+
* Copyright 2016 gRPC authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
package grpc
22+
23+
import (
24+
"fmt"
25+
"io"
26+
"net"
27+
"net/http"
28+
"os"
29+
30+
"golang.org/x/net/context"
31+
"google.golang.org/grpc/codes"
32+
"google.golang.org/grpc/status"
33+
"google.golang.org/grpc/transport"
34+
)
35+
36+
// dialContext connects to the address on the named network.
37+
func dialContext(ctx context.Context, network, address string) (net.Conn, error) {
38+
return (&net.Dialer{Cancel: ctx.Done()}).Dial(network, address)
39+
}
40+
41+
func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error {
42+
req.Cancel = ctx.Done()
43+
if err := req.Write(conn); err != nil {
44+
return fmt.Errorf("failed to write the HTTP request: %v", err)
45+
}
46+
return nil
47+
}
48+
49+
// toRPCErr converts an error into an error from the status package.
50+
func toRPCErr(err error) error {
51+
if _, ok := status.FromError(err); ok {
52+
return err
53+
}
54+
switch e := err.(type) {
55+
case transport.StreamError:
56+
return status.Error(e.Code, e.Desc)
57+
case transport.ConnectionError:
58+
return status.Error(codes.Unavailable, e.Desc)
59+
default:
60+
switch err {
61+
case context.DeadlineExceeded:
62+
return status.Error(codes.DeadlineExceeded, err.Error())
63+
case context.Canceled:
64+
return status.Error(codes.Canceled, err.Error())
65+
case ErrClientConnClosing:
66+
return status.Error(codes.FailedPrecondition, err.Error())
67+
}
68+
}
69+
return status.Error(codes.Unknown, err.Error())
70+
}
71+
72+
// convertCode converts a standard Go error into its canonical code. Note that
73+
// this is only used to translate the error returned by the server applications.
74+
func convertCode(err error) codes.Code {
75+
switch err {
76+
case nil:
77+
return codes.OK
78+
case io.EOF:
79+
return codes.OutOfRange
80+
case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF:
81+
return codes.FailedPrecondition
82+
case os.ErrInvalid:
83+
return codes.InvalidArgument
84+
case context.Canceled:
85+
return codes.Canceled
86+
case context.DeadlineExceeded:
87+
return codes.DeadlineExceeded
88+
}
89+
switch {
90+
case os.IsExist(err):
91+
return codes.AlreadyExists
92+
case os.IsNotExist(err):
93+
return codes.NotFound
94+
case os.IsPermission(err):
95+
return codes.PermissionDenied
96+
}
97+
return codes.Unknown
98+
}

go17.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// +build go1.7
2+
3+
/*
4+
*
5+
* Copyright 2016 gRPC authors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
package grpc
22+
23+
import (
24+
"context"
25+
"fmt"
26+
"io"
27+
"net"
28+
"net/http"
29+
"os"
30+
31+
netctx "golang.org/x/net/context"
32+
"google.golang.org/grpc/codes"
33+
"google.golang.org/grpc/status"
34+
"google.golang.org/grpc/transport"
35+
)
36+
37+
// dialContext connects to the address on the named network.
38+
func dialContext(ctx context.Context, network, address string) (net.Conn, error) {
39+
return (&net.Dialer{}).DialContext(ctx, network, address)
40+
}
41+
42+
func sendHTTPRequest(ctx context.Context, req *http.Request, conn net.Conn) error {
43+
req = req.WithContext(ctx)
44+
if err := req.Write(conn); err != nil {
45+
return fmt.Errorf("failed to write the HTTP request: %v", err)
46+
}
47+
return nil
48+
}
49+
50+
// toRPCErr converts an error into an error from the status package.
51+
func toRPCErr(err error) error {
52+
if _, ok := status.FromError(err); ok {
53+
return err
54+
}
55+
switch e := err.(type) {
56+
case transport.StreamError:
57+
return status.Error(e.Code, e.Desc)
58+
case transport.ConnectionError:
59+
return status.Error(codes.Unavailable, e.Desc)
60+
default:
61+
switch err {
62+
case context.DeadlineExceeded, netctx.DeadlineExceeded:
63+
return status.Error(codes.DeadlineExceeded, err.Error())
64+
case context.Canceled, netctx.Canceled:
65+
return status.Error(codes.Canceled, err.Error())
66+
case ErrClientConnClosing:
67+
return status.Error(codes.FailedPrecondition, err.Error())
68+
}
69+
}
70+
return status.Error(codes.Unknown, err.Error())
71+
}
72+
73+
// convertCode converts a standard Go error into its canonical code. Note that
74+
// this is only used to translate the error returned by the server applications.
75+
func convertCode(err error) codes.Code {
76+
switch err {
77+
case nil:
78+
return codes.OK
79+
case io.EOF:
80+
return codes.OutOfRange
81+
case io.ErrClosedPipe, io.ErrNoProgress, io.ErrShortBuffer, io.ErrShortWrite, io.ErrUnexpectedEOF:
82+
return codes.FailedPrecondition
83+
case os.ErrInvalid:
84+
return codes.InvalidArgument
85+
case context.Canceled, netctx.Canceled:
86+
return codes.Canceled
87+
case context.DeadlineExceeded, netctx.DeadlineExceeded:
88+
return codes.DeadlineExceeded
89+
}
90+
switch {
91+
case os.IsExist(err):
92+
return codes.AlreadyExists
93+
case os.IsNotExist(err):
94+
return codes.NotFound
95+
case os.IsPermission(err):
96+
return codes.PermissionDenied
97+
}
98+
return codes.Unknown
99+
}

naming/go17.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build go1.7, !go1.8
1+
// +build go1.6, !go1.8
22

33
/*
44
*

naming/go17_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build go1.7, !go1.8
1+
// +build go1.6, !go1.8
22

33
/*
44
*

proxy.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, addr string) (_
8282
Header: map[string][]string{"User-Agent": {grpcUA}},
8383
})
8484

85-
req = req.WithContext(ctx)
86-
if err := req.Write(conn); err != nil {
85+
if err := sendHTTPRequest(ctx, req, conn); err != nil {
8786
return nil, fmt.Errorf("failed to write the HTTP request: %v", err)
8887
}
8988

0 commit comments

Comments
 (0)