Skip to content

Commit

Permalink
tweak output layout (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktr0731 authored Apr 29, 2020
1 parent 3dbcdbf commit 2134fc2
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
"header_val2"
]
},
"messages": [
{}
],
"trailer": {
"trailer_key1": [
"trailer_val1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ content-type: application/grpc
header_key1: header_val1
header_key2: header_val2

{}

trailer_key1: trailer_val1
trailer_key2: trailer_val2

Expand All @@ -13,3 +11,4 @@ message: "internal error"
details:
{"@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [{"description": "description", "field": "field"}]}
{"@type": "type.googleapis.com/google.rpc.PreconditionFailure", "violations": [{"description": "description", "subject": "subject", "type": "type"}]}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ header_key1: header_val1
header_key2: header_val2
vary: Origin

{}

trailer_key1: trailer_val1
trailer_key2: trailer_val2

Expand All @@ -14,3 +12,4 @@ message: "internal error"
details:
{"@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [{"description": "description", "field": "field"}]}
{"@type": "type.googleapis.com/google.rpc.PreconditionFailure", "violations": [{"description": "description", "subject": "subject", "type": "type"}]}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ content-type: application/grpc
header_key1: header_val1
header_key2: header_val2

{}

trailer_key1: trailer_val1
trailer_key2: trailer_val2

Expand All @@ -16,3 +14,4 @@ details:
{"@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [{"description": "description", "field": "field"}]}
{"@type": "type.googleapis.com/google.rpc.PreconditionFailure", "violations": [{"description": "description", "subject": "subject", "type": "type"}]}


4 changes: 4 additions & 0 deletions format/curl/curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ktr0731/evans/present/json"
"github.com/pkg/errors"
_ "google.golang.org/genproto/googleapis/rpc/errdetails" // For calling RegisterType.
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -118,6 +119,9 @@ func (p *responseFormatter) FormatStatus(status *status.Status) error {
}
fmt.Fprintf(p.w, "details: \n%s\n", strings.Join(details, "\n"))
}
if status.Code() != codes.OK {
fmt.Fprintf(p.w, "\n")
}
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package format

import (
"github.com/golang/protobuf/ptypes/empty"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -33,7 +32,7 @@ func (f *ResponseFormatter) FormatHeader(header metadata.MD) {

func (f *ResponseFormatter) FormatMessage(v interface{}) error {
if v == nil {
v = &empty.Empty{}
return nil
}
return f.impl.FormatMessage(v)
}
Expand Down

0 comments on commit 2134fc2

Please sign in to comment.