Skip to content

Commit dcb8443

Browse files
authored
Merge pull request #182 from gengo/cleanup/lint
Fix golint and go vet errors
2 parents c53c4e9 + fb389be commit dcb8443

File tree

11 files changed

+52
-39
lines changed

11 files changed

+52
-39
lines changed

.travis.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ script:
2323
- make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar"
2424
- if ! go version | grep devel; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi
2525
- env GLOG_logtostderr=1 go test -race -v github.com/gengo/grpc-gateway/...
26-
- golint github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/...
27-
- golint github.com/gengo/grpc-gateway/runtime/...
28-
- golint github.com/gengo/grpc-gateway/utilities/...
29-
- go vet github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/...
30-
- go vet github.com/gengo/grpc-gateway/runtime/... || true
31-
- go vet github.com/gengo/grpc-gateway/utilities/...
26+
- make lint
3227
env:
3328
global:
3429
- "PATH=$PATH:$HOME/local/bin"

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ OPTIONS_PROTO=$(GOOGLEAPIS_DIR)/google/api/annotations.proto $(GOOGLEAPIS_DIR)/g
4141
OPTIONS_GO=$(OPTIONS_PROTO:.proto=.pb.go)
4242
OUTPUT_DIR=_output
4343

44-
RUNTIME_PROTO=runtime/stream_chunk.proto
44+
RUNTIME_PROTO=runtime/internal/stream_chunk.proto
4545
RUNTIME_GO=$(RUNTIME_PROTO:.proto=.pb.go)
4646

4747
PKGMAP=Mgoogle/protobuf/descriptor.proto=$(GO_PLUGIN_PKG)/descriptor,Mgoogle/api/annotations.proto=$(PKG)/$(GOOGLEAPIS_DIR)/google/api,Mexamples/sub/message.proto=$(PKG)/examples/sub
@@ -119,6 +119,16 @@ examples: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS) $(EXAMPLE_SWAG
119119
test: examples
120120
go test -race $(PKG)/...
121121

122+
lint:
123+
golint --set_exit_status $(PKG)/runtime
124+
golint --set_exit_status $(PKG)/utilities/...
125+
golint --set_exit_status $(PKG)/protoc-gen-grpc-gateway/...
126+
golint --set_exit_status $(PKG)/protoc-gen-swagger/...
127+
go vet $(PKG)/runtime || true
128+
go vet $(PKG)/utilities/...
129+
go vet $(PKG)/protoc-gen-grpc-gateway/...
130+
go vet $(PKG)/protoc-gen-swagger/...
131+
122132
clean distclean:
123133
rm -f $(GATEWAY_PLUGIN)
124134
realclean: distclean
@@ -130,4 +140,4 @@ realclean: distclean
130140
rm -f $(SWAGGER_PLUGIN)
131141
rm -f $(EXAMPLE_CLIENT_SRCS)
132142

133-
.PHONY: generate examples test clean distclean realclean
143+
.PHONY: generate examples test lint clean distclean realclean

protoc-gen-swagger/genswagger/generator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
12+
gen "github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/generator"
1213
"github.com/golang/glog"
1314
"github.com/golang/protobuf/proto"
1415
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
@@ -23,7 +24,7 @@ type generator struct {
2324
}
2425

2526
// New returns a new generator which generates grpc gateway files.
26-
func New(reg *descriptor.Registry) *generator {
27+
func New(reg *descriptor.Registry) gen.Generator {
2728
return &generator{reg: reg}
2829
}
2930

protoc-gen-swagger/genswagger/template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ func templateToSwaggerPath(path string) string {
293293
switch char {
294294
case '{':
295295
// Push on the stack
296-
depth += 1
296+
depth++
297297
buffer += string(char)
298298
break
299299
case '}':
300300
if depth == 0 {
301301
panic("Encountered } without matching { before it.")
302302
}
303303
// Pop from the stack
304-
depth -= 1
304+
depth--
305305
buffer += "}"
306306
case '/':
307307
if depth == 0 {
@@ -389,7 +389,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
389389
methProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.ServiceDescriptorProto)(nil)), "Method")
390390
operationObject := &swaggerOperationObject{
391391
Tags: []string{svc.GetName()},
392-
OperationId: fmt.Sprintf("%s", meth.GetName()),
392+
OperationID: fmt.Sprintf("%s", meth.GetName()),
393393
Parameters: parameters,
394394
Responses: swaggerResponsesObject{
395395
"200": swaggerResponseObject{

protoc-gen-swagger/genswagger/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type swaggerPathItemObject struct {
7272
type swaggerOperationObject struct {
7373
Summary string `json:"summary,omitempty"`
7474
Description string `json:"description,omitempty"`
75-
OperationId string `json:"operationId"`
75+
OperationID string `json:"operationId"`
7676
Responses swaggerResponsesObject `json:"responses"`
7777
Parameters swaggerParametersObject `json:"parameters,omitempty"`
7878
Tags []string `json:"tags,omitempty"`

runtime/context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func TestAnnotateContext_ForwardsGrpcMetadata(t *testing.T) {
5151
return
5252
}
5353
md, ok := metadata.FromContext(annotated)
54-
if !ok || len(md) != emptyForwardMetaCount+3 {
55-
t.Errorf("Expected %d metadata items in context; got %v", md)
54+
if got, want := len(md), emptyForwardMetaCount+3; !ok || got != want {
55+
t.Errorf("Expected %d metadata items in context; got %d", got, want)
5656
}
5757
if got, want := md["foobar"], []string{"Value1"}; !reflect.DeepEqual(got, want) {
5858
t.Errorf(`md["foobar"] = %q; want %q`, got, want)

runtime/errors.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"net/http"
66

77
"github.com/golang/protobuf/proto"
8-
98
"golang.org/x/net/context"
109
"google.golang.org/grpc"
1110
"google.golang.org/grpc/codes"
@@ -59,7 +58,7 @@ var (
5958
// HTTPError replies to the request with the error.
6059
// You can set a custom function to this variable to customize error format.
6160
HTTPError = DefaultHTTPError
62-
// This handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest
61+
// OtherErrorHandler handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest
6362
OtherErrorHandler = DefaultOtherErrorHandler
6463
)
6564

@@ -114,6 +113,8 @@ func DefaultHTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseW
114113
handleForwardResponseTrailer(w, md)
115114
}
116115

117-
func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, error string, code int) {
118-
http.Error(w, error, code)
116+
// DefaultOtherErrorHandler is the default implementation of OtherErrorHandler.
117+
// It simply writes a string representation of the given error into "w".
118+
func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) {
119+
http.Error(w, msg, code)
119120
}

runtime/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/textproto"
88

9+
"github.com/gengo/grpc-gateway/runtime/internal"
910
"github.com/golang/protobuf/proto"
1011
"golang.org/x/net/context"
1112
"google.golang.org/grpc"
@@ -148,7 +149,7 @@ func streamChunk(result proto.Message, err error) map[string]proto.Message {
148149
grpcCode := grpc.Code(err)
149150
httpCode := HTTPStatusFromCode(grpcCode)
150151
return map[string]proto.Message{
151-
"error": &StreamError{
152+
"error": &internal.StreamError{
152153
GrpcCode: int32(grpcCode),
153154
HttpCode: int32(httpCode),
154155
Message: err.Error(),
Lines changed: 20 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
syntax = "proto3";
22
package gengo.grpc.gateway.runtime;
3-
option go_package = "runtime";
3+
option go_package = "internal";
44

5+
// StreamError is a response type which is returned when
6+
// streaming rpc returns an error.
57
message StreamError {
68
int32 grpc_code = 1;
79
int32 http_code = 2;

0 commit comments

Comments
 (0)