本文整理汇总了Golang中github.com/grpc-ecosystem/grpc-gateway/runtime.JSONBuiltin.NewDecoder方法的典型用法代码示例。如果您正苦于以下问题:Golang JSONBuiltin.NewDecoder方法的具体用法?Golang JSONBuiltin.NewDecoder怎么用?Golang JSONBuiltin.NewDecoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/grpc-ecosystem/grpc-gateway/runtime.JSONBuiltin
的用法示例。
在下文中一共展示了JSONBuiltin.NewDecoder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestJSONBuiltinDecoderFields
func TestJSONBuiltinDecoderFields(t *testing.T) {
var m runtime.JSONBuiltin
for _, fixt := range builtinFieldFixtures {
r := strings.NewReader(fixt.json)
dec := m.NewDecoder(r)
dest := reflect.New(reflect.TypeOf(fixt.data))
if err := dec.Decode(dest.Interface()); err != nil {
t.Errorf("dec.Decode(dest) failed with %v; want success; data = %q", err, fixt.json)
}
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want = %v; input = %q", got, want, fixt.json)
}
}
}
示例2: TestJSONBuiltinDecoder
func TestJSONBuiltinDecoder(t *testing.T) {
var (
m runtime.JSONBuiltin
got examplepb.SimpleMessage
data = `{"id": "foo"}`
)
r := strings.NewReader(data)
dec := m.NewDecoder(r)
if err := dec.Decode(&got); err != nil {
t.Errorf("m.Unmarshal(&got) failed with %v; want success", err)
}
want := examplepb.SimpleMessage{
Id: "foo",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want = %v", &got, &want)
}
}