forked from keratin/authn-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The JSON encoder/decoder provided by gRPC-gateway runtime silently co…
…nverts (u)int64 to strings (see: grpc-ecosystem/grpc-gateway#920 ), which is compliant with the Proto3 spec. However, this affects our response negatively because it breaks backwards compatibilty. Go's JSON encoder/decoder doesn't have such surprises. This commit replaces runtime.JSONPb (from gRPC-Gateway) with a wrapper around the stdlib JSON encoder/decoder.
- Loading branch information
1 parent
655feb9
commit 21b06d9
Showing
4 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gateway | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
) | ||
|
||
// customJSONMarshaler implements runtime.Marshaler | ||
type customJSONMarshaler struct{} | ||
|
||
// Marshal marshals "v" into byte sequence. | ||
func (j *customJSONMarshaler) Marshal(v interface{}) ([]byte, error) { | ||
return json.Marshal(v) | ||
} | ||
|
||
// Unmarshal unmarshals "data" into "v". | ||
func (j *customJSONMarshaler) Unmarshal(data []byte, v interface{}) error { | ||
return json.Unmarshal(data, v) | ||
} | ||
|
||
// NewDecoder returns a Decoder which reads byte sequence from "r". | ||
func (j *customJSONMarshaler) NewDecoder(r io.Reader) runtime.Decoder { | ||
return json.NewDecoder(r) | ||
} | ||
|
||
// NewEncoder returns an Encoder which writes bytes sequence into "w". | ||
func (j *customJSONMarshaler) NewEncoder(w io.Writer) runtime.Encoder { | ||
return json.NewEncoder(w) | ||
} | ||
|
||
// ContentType returns the Content-Type which this marshaler is responsible for. | ||
func (j *customJSONMarshaler) ContentType() string { | ||
return "application/json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters