Skip to content

Commit 37f01f3

Browse files
committed
Rework build to use GitHub Actions, linting updates.
1 parent 0f1106e commit 37f01f3

File tree

9 files changed

+150
-68
lines changed

9 files changed

+150
-68
lines changed

.github/workflows/go.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Go
2+
on: [push]
3+
jobs:
4+
5+
build:
6+
name: Build
7+
runs-on: ubuntu-latest
8+
steps:
9+
10+
- name: Set up Go 1.13
11+
uses: actions/setup-go@v1
12+
with:
13+
go-version: 1.13
14+
id: go
15+
16+
- name: Check out code into the Go module directory
17+
uses: actions/checkout@v1
18+
19+
- name: Get dependencies
20+
run: |
21+
go mod download
22+
go mod verify
23+
go list -mod=readonly all >/dev/null
24+
25+
- name: Test
26+
run: go test -v ./...
27+
28+
lint:
29+
name: Lint
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Check out code into the Go module directory
33+
uses: actions/checkout@v1
34+
35+
- name: Run GolangCI-Lint
36+
uses: actions-contrib/golangci-lint@master
37+
with:
38+
args: run

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# gRPC Proxy
22

3-
[![Travis Build](https://travis-ci.org/mwitkow/grpc-proxy.svg?branch=master)](https://travis-ci.org/mwitkow/grpc-proxy)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/mwitkow/grpc-proxy)](https://goreportcard.com/report/github.com/mwitkow/grpc-proxy)
5-
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/mwitkow/grpc-proxy)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/smira/grpc-proxy)](https://goreportcard.com/report/github.com/smira/grpc-proxy)
4+
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/smira/grpc-proxy)
65
[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
76

87
[gRPC Go](https://github.com/grpc/grpc-go) Proxy server
@@ -56,4 +55,3 @@ pb_test.RegisterTestServiceServer(server, &testImpl{})
5655
## License
5756

5857
`grpc-proxy` is released under the Apache 2.0 license. See [LICENSE.txt](LICENSE.txt).
59-

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/smira/grpc-proxy
2+
3+
go 1.13
4+
5+
require (
6+
github.com/golang/protobuf v1.3.2
7+
github.com/stretchr/testify v1.4.0
8+
golang.org/x/net v0.0.0-20191116160921-f9c825593386
9+
google.golang.org/grpc v1.25.1
10+
)

go.sum

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4+
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
6+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7+
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
8+
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
9+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
10+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
11+
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
12+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
13+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
14+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
15+
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
16+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
17+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
19+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
20+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
21+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
22+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
23+
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
24+
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
25+
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
26+
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
27+
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
28+
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
29+
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
30+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
31+
golang.org/x/net v0.0.0-20191116160921-f9c825593386 h1:ktbWvQrW08Txdxno1PiDpSxPXG6ndGsfnJjRRtkM0LQ=
32+
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
33+
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
34+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
35+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
36+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
37+
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
38+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
39+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
40+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
41+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
42+
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
43+
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
44+
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
45+
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
46+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
47+
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
48+
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
49+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
50+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
51+
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
52+
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
53+
google.golang.org/grpc v1.25.1 h1:wdKvqQk7IttEw92GoRyKG2IDrUIpgpj6H6m81yfeMW0=
54+
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
55+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
56+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
57+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
58+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
59+
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
60+
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

proxy/codec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
// Codec returns a proxying grpc.Codec with the default protobuf codec as parent.
1111
//
1212
// See CodecWithParent.
13+
//
14+
//nolint: staticcheck
1315
func Codec() grpc.Codec {
1416
return CodecWithParent(&protoCodec{})
1517
}
@@ -20,12 +22,14 @@ func Codec() grpc.Codec {
2022
// to the schema of the forwarded messages. It basically treats a gRPC message frame as raw bytes.
2123
// However, if the server handler, or the client caller are not proxy-internal functions it will fall back
2224
// to trying to decode the message using a fallback codec.
25+
//
26+
//nolint: staticcheck
2327
func CodecWithParent(fallback grpc.Codec) grpc.Codec {
2428
return &rawCodec{fallback}
2529
}
2630

2731
type rawCodec struct {
28-
parentCodec grpc.Codec
32+
parentCodec grpc.Codec //nolint: staticcheck
2933
}
3034

3135
type frame struct {

proxy/examples_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ package proxy_test
66
import (
77
"strings"
88

9-
"github.com/mwitkow/grpc-proxy/proxy"
109
"golang.org/x/net/context"
1110
"google.golang.org/grpc"
1211
"google.golang.org/grpc/codes"
1312
"google.golang.org/grpc/metadata"
13+
"google.golang.org/grpc/status"
14+
15+
"github.com/smira/grpc-proxy/proxy"
1416
)
1517

1618
var (
@@ -38,7 +40,7 @@ func ExampleStreamDirector() {
3840
director = func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) {
3941
// Make sure we never forward internal services.
4042
if strings.HasPrefix(fullMethodName, "/com.example.internal.") {
41-
return nil, nil, grpc.Errorf(codes.Unimplemented, "Unknown method")
43+
return nil, nil, status.Errorf(codes.Unimplemented, "Unknown method")
4244
}
4345
md, ok := metadata.FromIncomingContext(ctx)
4446
// Copy the inbound metadata explicitly.
@@ -48,13 +50,13 @@ func ExampleStreamDirector() {
4850
// Decide on which backend to dial
4951
if val, exists := md[":authority"]; exists && val[0] == "staging.api.example.com" {
5052
// Make sure we use DialContext so the dialing can be cancelled/time out together with the context.
51-
conn, err := grpc.DialContext(ctx, "api-service.staging.svc.local", grpc.WithCodec(proxy.Codec()))
53+
conn, err := grpc.DialContext(ctx, "api-service.staging.svc.local", grpc.WithCodec(proxy.Codec())) // nolint: staticcheck
5254
return outCtx, conn, err
5355
} else if val, exists := md[":authority"]; exists && val[0] == "api.example.com" {
54-
conn, err := grpc.DialContext(ctx, "api-service.prod.svc.local", grpc.WithCodec(proxy.Codec()))
56+
conn, err := grpc.DialContext(ctx, "api-service.prod.svc.local", grpc.WithCodec(proxy.Codec())) // nolint: staticcheck
5557
return outCtx, conn, err
5658
}
5759
}
58-
return nil, nil, grpc.Errorf(codes.Unimplemented, "Unknown method")
60+
return nil, nil, status.Errorf(codes.Unimplemented, "Unknown method")
5961
}
6062
}

proxy/handler.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"golang.org/x/net/context"
1010
"google.golang.org/grpc"
1111
"google.golang.org/grpc/codes"
12+
"google.golang.org/grpc/status"
1213
)
1314

1415
var (
@@ -61,7 +62,7 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error
6162
// little bit of gRPC internals never hurt anyone
6263
fullMethodName, ok := grpc.MethodFromServerStream(serverStream)
6364
if !ok {
64-
return grpc.Errorf(codes.Internal, "lowLevelServerStream not exists in context")
65+
return status.Errorf(codes.Internal, "lowLevelServerStream not exists in context")
6566
}
6667
// We require that the director's returned context inherits from the serverStream.Context().
6768
outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName)
@@ -87,14 +88,15 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error
8788
if s2cErr == io.EOF {
8889
// this is the happy case where the sender has encountered io.EOF, and won't be sending anymore./
8990
// the clientStream>serverStream may continue pumping though.
91+
//nolint: errcheck
9092
clientStream.CloseSend()
9193
break
9294
} else {
9395
// however, we may have gotten a receive error (stream disconnected, a read error etc) in which case we need
9496
// to cancel the clientStream to the backend, let all of its goroutines be freed up by the CancelFunc and
9597
// exit with an error to the stack
9698
clientCancel()
97-
return grpc.Errorf(codes.Internal, "failed proxying s2c: %v", s2cErr)
99+
return status.Errorf(codes.Internal, "failed proxying s2c: %v", s2cErr)
98100
}
99101
case c2sErr := <-c2sErrChan:
100102
// This happens when the clientStream has nothing else to offer (io.EOF), returned a gRPC error. In those two
@@ -108,7 +110,7 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error
108110
return nil
109111
}
110112
}
111-
return grpc.Errorf(codes.Internal, "gRPC proxying should never reach this stage.")
113+
return status.Errorf(codes.Internal, "gRPC proxying should never reach this stage.")
112114
}
113115

114116
func (s *handler) forwardClientToServer(src grpc.ClientStream, dst grpc.ServerStream) chan error {

0 commit comments

Comments
 (0)