當前位置: 首頁>>代碼示例>>Golang>>正文


Golang JSONBuiltin.Marshal方法代碼示例

本文整理匯總了Golang中github.com/gengo/grpc-gateway/runtime.JSONBuiltin.Marshal方法的典型用法代碼示例。如果您正苦於以下問題:Golang JSONBuiltin.Marshal方法的具體用法?Golang JSONBuiltin.Marshal怎麽用?Golang JSONBuiltin.Marshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gengo/grpc-gateway/runtime.JSONBuiltin的用法示例。


在下文中一共展示了JSONBuiltin.Marshal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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:digitalfishpond,項目名稱:dashboard,代碼行數:12,代碼來源:marshal_json_test.go

示例2: 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:digitalfishpond,項目名稱:dashboard,代碼行數:19,代碼來源:marshal_json_test.go


注:本文中的github.com/gengo/grpc-gateway/runtime.JSONBuiltin.Marshal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。