Skip to content

Commit

Permalink
Merge pull request #182 from gengo/cleanup/lint
Browse files Browse the repository at this point in the history
Fix golint and go vet errors
  • Loading branch information
yugui authored Jun 14, 2016
2 parents c53c4e9 + fb389be commit dcb8443
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 39 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ script:
- make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar"
- if ! go version | grep devel; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi
- env GLOG_logtostderr=1 go test -race -v github.com/gengo/grpc-gateway/...
- golint github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/...
- golint github.com/gengo/grpc-gateway/runtime/...
- golint github.com/gengo/grpc-gateway/utilities/...
- go vet github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/...
- go vet github.com/gengo/grpc-gateway/runtime/... || true
- go vet github.com/gengo/grpc-gateway/utilities/...
- make lint
env:
global:
- "PATH=$PATH:$HOME/local/bin"
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ OPTIONS_PROTO=$(GOOGLEAPIS_DIR)/google/api/annotations.proto $(GOOGLEAPIS_DIR)/g
OPTIONS_GO=$(OPTIONS_PROTO:.proto=.pb.go)
OUTPUT_DIR=_output

RUNTIME_PROTO=runtime/stream_chunk.proto
RUNTIME_PROTO=runtime/internal/stream_chunk.proto
RUNTIME_GO=$(RUNTIME_PROTO:.proto=.pb.go)

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
Expand Down Expand Up @@ -119,6 +119,16 @@ examples: $(EXAMPLE_SVCSRCS) $(EXAMPLE_GWSRCS) $(EXAMPLE_DEPSRCS) $(EXAMPLE_SWAG
test: examples
go test -race $(PKG)/...

lint:
golint --set_exit_status $(PKG)/runtime
golint --set_exit_status $(PKG)/utilities/...
golint --set_exit_status $(PKG)/protoc-gen-grpc-gateway/...
golint --set_exit_status $(PKG)/protoc-gen-swagger/...
go vet $(PKG)/runtime || true
go vet $(PKG)/utilities/...
go vet $(PKG)/protoc-gen-grpc-gateway/...
go vet $(PKG)/protoc-gen-swagger/...

clean distclean:
rm -f $(GATEWAY_PLUGIN)
realclean: distclean
Expand All @@ -130,4 +140,4 @@ realclean: distclean
rm -f $(SWAGGER_PLUGIN)
rm -f $(EXAMPLE_CLIENT_SRCS)

.PHONY: generate examples test clean distclean realclean
.PHONY: generate examples test lint clean distclean realclean
3 changes: 2 additions & 1 deletion protoc-gen-swagger/genswagger/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
gen "github.com/gengo/grpc-gateway/protoc-gen-grpc-gateway/generator"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
Expand All @@ -23,7 +24,7 @@ type generator struct {
}

// New returns a new generator which generates grpc gateway files.
func New(reg *descriptor.Registry) *generator {
func New(reg *descriptor.Registry) gen.Generator {
return &generator{reg: reg}
}

Expand Down
6 changes: 3 additions & 3 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ func templateToSwaggerPath(path string) string {
switch char {
case '{':
// Push on the stack
depth += 1
depth++
buffer += string(char)
break
case '}':
if depth == 0 {
panic("Encountered } without matching { before it.")
}
// Pop from the stack
depth -= 1
depth--
buffer += "}"
case '/':
if depth == 0 {
Expand Down Expand Up @@ -389,7 +389,7 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
methProtoPath := protoPathIndex(reflect.TypeOf((*pbdescriptor.ServiceDescriptorProto)(nil)), "Method")
operationObject := &swaggerOperationObject{
Tags: []string{svc.GetName()},
OperationId: fmt.Sprintf("%s", meth.GetName()),
OperationID: fmt.Sprintf("%s", meth.GetName()),
Parameters: parameters,
Responses: swaggerResponsesObject{
"200": swaggerResponseObject{
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-swagger/genswagger/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type swaggerPathItemObject struct {
type swaggerOperationObject struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationId string `json:"operationId"`
OperationID string `json:"operationId"`
Responses swaggerResponsesObject `json:"responses"`
Parameters swaggerParametersObject `json:"parameters,omitempty"`
Tags []string `json:"tags,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions runtime/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestAnnotateContext_ForwardsGrpcMetadata(t *testing.T) {
return
}
md, ok := metadata.FromContext(annotated)
if !ok || len(md) != emptyForwardMetaCount+3 {
t.Errorf("Expected %d metadata items in context; got %v", md)
if got, want := len(md), emptyForwardMetaCount+3; !ok || got != want {
t.Errorf("Expected %d metadata items in context; got %d", got, want)
}
if got, want := md["foobar"], []string{"Value1"}; !reflect.DeepEqual(got, want) {
t.Errorf(`md["foobar"] = %q; want %q`, got, want)
Expand Down
9 changes: 5 additions & 4 deletions runtime/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"

"github.com/golang/protobuf/proto"

"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -59,7 +58,7 @@ var (
// HTTPError replies to the request with the error.
// You can set a custom function to this variable to customize error format.
HTTPError = DefaultHTTPError
// This handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest
// OtherErrorHandler handles the following error used by the gateway: StatusMethodNotAllowed StatusNotFound and StatusBadRequest
OtherErrorHandler = DefaultOtherErrorHandler
)

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

func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, error string, code int) {
http.Error(w, error, code)
// DefaultOtherErrorHandler is the default implementation of OtherErrorHandler.
// It simply writes a string representation of the given error into "w".
func DefaultOtherErrorHandler(w http.ResponseWriter, _ *http.Request, msg string, code int) {
http.Error(w, msg, code)
}
3 changes: 2 additions & 1 deletion runtime/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/textproto"

"github.com/gengo/grpc-gateway/runtime/internal"
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
Expand Down Expand Up @@ -148,7 +149,7 @@ func streamChunk(result proto.Message, err error) map[string]proto.Message {
grpcCode := grpc.Code(err)
httpCode := HTTPStatusFromCode(grpcCode)
return map[string]proto.Message{
"error": &StreamError{
"error": &internal.StreamError{
GrpcCode: int32(grpcCode),
HttpCode: int32(httpCode),
Message: err.Error(),
Expand Down
37 changes: 20 additions & 17 deletions runtime/stream_chunk.pb.go → runtime/internal/stream_chunk.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
syntax = "proto3";
package gengo.grpc.gateway.runtime;
option go_package = "runtime";
option go_package = "internal";

// StreamError is a response type which is returned when
// streaming rpc returns an error.
message StreamError {
int32 grpc_code = 1;
int32 http_code = 2;
Expand Down
2 changes: 1 addition & 1 deletion runtime/marshaler_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

// MIMEWildCard is the fallback MIME type used for requests which do not match
// MIMEWildcard is the fallback MIME type used for requests which do not match
// a registered MIME type.
const MIMEWildcard = "*"

Expand Down

0 comments on commit dcb8443

Please sign in to comment.