当前位置: 首页>>代码示例>>Golang>>正文


Golang runtime.JSONBuiltin类代码示例

本文整理汇总了Golang中github.com/grpc-ecosystem/grpc-gateway/runtime.JSONBuiltin的典型用法代码示例。如果您正苦于以下问题:Golang JSONBuiltin类的具体用法?Golang JSONBuiltin怎么用?Golang JSONBuiltin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JSONBuiltin类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
		}
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:9,代码来源:marshal_json_test.go

示例2: TestJSONBuiltinMarshalFieldKnownErrors

func TestJSONBuiltinMarshalFieldKnownErrors(t *testing.T) {
	var m runtime.JSONBuiltin
	for _, fixt := range builtinKnownErrors {
		buf, err := m.Marshal(fixt.data)
		if err != nil {
			t.Errorf("m.Marshal(%v) failed with %v; want success", fixt.data, err)
		}
		if got, want := string(buf), fixt.json; got == want {
			t.Errorf("surprisingly got = %q; as want %q; data = %#v", got, want, fixt.data)
		}
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:12,代码来源:marshal_json_test.go

示例3: 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)
		}
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:13,代码来源:marshal_json_test.go

示例4: TestJSONBuiltinEncoderFields

func TestJSONBuiltinEncoderFields(t *testing.T) {
	var m runtime.JSONBuiltin
	for _, fixt := range builtinFieldFixtures {
		var buf bytes.Buffer
		enc := m.NewEncoder(&buf)
		if err := enc.Encode(fixt.data); err != nil {
			t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
		}

		if got, want := buf.String(), fixt.json+"\n"; got != want {
			t.Errorf("got = %q; want %q; data = %#v", got, want, fixt.data)
		}
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:14,代码来源:marshal_json_test.go

示例5: 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)
		}
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:15,代码来源:marshal_json_test.go

示例6: 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)
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:18,代码来源:marshal_json_test.go

示例7: TestJSONBuiltinMarshal

func TestJSONBuiltinMarshal(t *testing.T) {
	var m runtime.JSONBuiltin
	msg := examplepb.SimpleMessage{
		Id: "foo",
	}

	buf, err := m.Marshal(&msg)
	if err != nil {
		t.Errorf("m.Marshal(%v) failed with %v; want success", &msg, err)
	}

	var got examplepb.SimpleMessage
	if err := json.Unmarshal(buf, &got); err != nil {
		t.Errorf("json.Unmarshal(%q, &got) failed with %v; want success", buf, err)
	}
	if want := msg; !reflect.DeepEqual(got, want) {
		t.Errorf("got = %v; want %v", &got, &want)
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:19,代码来源:marshal_json_test.go

示例8: 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)
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:20,代码来源:marshal_json_test.go

示例9: TestJSONBuiltinEncoder

func TestJSONBuiltinEncoder(t *testing.T) {
	var m runtime.JSONBuiltin
	msg := examplepb.SimpleMessage{
		Id: "foo",
	}

	var buf bytes.Buffer
	enc := m.NewEncoder(&buf)
	if err := enc.Encode(&msg); err != nil {
		t.Errorf("enc.Encode(%v) failed with %v; want success", &msg, err)
	}

	var got examplepb.SimpleMessage
	if err := json.Unmarshal(buf.Bytes(), &got); err != nil {
		t.Errorf("json.Unmarshal(%q, &got) failed with %v; want success", buf.String(), err)
	}
	if want := msg; !reflect.DeepEqual(got, want) {
		t.Errorf("got = %v; want %v", &got, &want)
	}
}
开发者ID:kubernetes,项目名称:dashboard,代码行数:20,代码来源:marshal_json_test.go


注:本文中的github.com/grpc-ecosystem/grpc-gateway/runtime.JSONBuiltin类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。