本文整理匯總了Golang中github.com/gengo/grpc-gateway/runtime.JSONBuiltin.Unmarshal方法的典型用法代碼示例。如果您正苦於以下問題:Golang JSONBuiltin.Unmarshal方法的具體用法?Golang JSONBuiltin.Unmarshal怎麽用?Golang JSONBuiltin.Unmarshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gengo/grpc-gateway/runtime.JSONBuiltin
的用法示例。
在下文中一共展示了JSONBuiltin.Unmarshal方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestJSONBuiltinUnmarshalFieldKnownErrors
func TestJSONBuiltinUnmarshalFieldKnownErrors(t *testing.T) {
var m runtime.JSONBuiltin
for _, fixt := range builtinKnownErrors {
dest := reflect.New(reflect.TypeOf(fixt.data))
if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err == nil {
t.Errorf("m.Unmarshal(%q, dest) succeeded; want ane error", fixt.json)
}
}
}
示例2: TestJSONBuiltinUnmarshalField
func TestJSONBuiltinUnmarshalField(t *testing.T) {
var m runtime.JSONBuiltin
for _, fixt := range builtinFieldFixtures {
dest := reflect.New(reflect.TypeOf(fixt.data))
if err := m.Unmarshal([]byte(fixt.json), dest.Interface()); err != nil {
t.Errorf("m.Unmarshal(%q, dest) failed with %v; want success", fixt.json, err)
}
if got, want := dest.Elem().Interface(), fixt.data; !reflect.DeepEqual(got, want) {
t.Errorf("got = %#v; want = %#v; input = %q", got, want, fixt.json)
}
}
}
示例3: TestJSONBuiltinsnmarshal
func TestJSONBuiltinsnmarshal(t *testing.T) {
var (
m runtime.JSONBuiltin
got examplepb.SimpleMessage
data = []byte(`{"id": "foo"}`)
)
if err := m.Unmarshal(data, &got); err != nil {
t.Errorf("m.Unmarshal(%q, &got) failed with %v; want success", data, err)
}
want := examplepb.SimpleMessage{
Id: "foo",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got = %v; want = %v", &got, &want)
}
}