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


Golang jsonpb.Marshaler类代码示例

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


在下文中一共展示了Marshaler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestMoreDefaultsBJSON

func TestMoreDefaultsBJSON(t *testing.T) {
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
	p := NewPopulatedMoreDefaultsB(popr, true)
	marshaler := github_com_maditya_protobuf_jsonpb.Marshaler{}
	jsondata, err := marshaler.MarshalToString(p)
	if err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
	}
	msg := &MoreDefaultsB{}
	err = github_com_maditya_protobuf_jsonpb.UnmarshalString(jsondata, msg)
	if err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:18,代码来源:mdpb_test.go

示例2: TestEncodedSignedEntryUpdateJSON

func TestEncodedSignedEntryUpdateJSON(t *testing.T) {
	popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
	p := NewPopulatedEncodedSignedEntryUpdate(popr, true)
	marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
	jsondata, err := marshaler.MarshalToString(p)
	if err != nil {
		t.Fatal(err)
	}
	msg := &EncodedSignedEntryUpdate{}
	err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
	if err != nil {
		t.Fatal(err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("%#v !Json Equal %#v", msg, p)
	}
}
开发者ID:yahoo,项目名称:coname,代码行数:20,代码来源:SignedEntryUpdatepr_test.go

示例3: TestWilsonJSON

func TestWilsonJSON(t *testing.T) {
	seed := time.Now().UnixNano()
	popr := math_rand.New(math_rand.NewSource(seed))
	p := NewPopulatedWilson(popr, true)
	marshaler := github_com_maditya_protobuf_jsonpb.Marshaler{}
	jsondata, err := marshaler.MarshalToString(p)
	if err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
	}
	msg := &Wilson{}
	err = github_com_maditya_protobuf_jsonpb.UnmarshalString(jsondata, msg)
	if err != nil {
		t.Fatalf("seed = %d, err = %v", seed, err)
	}
	if err := p.VerboseEqual(msg); err != nil {
		t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
	}
	if !p.Equal(msg) {
		t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
	}
}
开发者ID:maditya,项目名称:protobuf,代码行数:21,代码来源:castvaluepb_test.go

示例4: ServeHTTP

func (h *HTTPFront) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path
	method := r.Method

	// service healthcheck
	if (method == "HEAD" || method == "GET") && (path == "/status" || path == "/lb") {
		if !h.InRotation() {
			http.Error(w, `server out of rotation`, http.StatusNotFound)
			return
		}
		if method == "GET" {
			w.Write([]byte("OK"))
		}
		return
	}

	if method == "GET" && path == "/saml" {
		url, err := h.SAMLRequest()
		if err != nil {
			http.Error(w, err.Error(), http.StatusNotFound)
			return
		}
		http.Redirect(w, r, url, http.StatusFound)
		return
	}
	if method == "GET" && path == "/oidc" {
		u, err := url.ParseQuery(r.URL.RawQuery)
		if err != nil {
			http.Error(w, `error parsing query string`, http.StatusBadRequest)
			return
		}
		d := u.Get("domain")
		if d == "" {
			http.Error(w, `domain not found`, http.StatusBadRequest)
			return
		}

		url, err := h.OIDCRequest(d, "https://"+r.Host+"/oidcsso")
		if err != nil {
			http.Error(w, err.Error(), http.StatusNotFound)
			return
		}
		http.Redirect(w, r, url, http.StatusFound)
	}

	if method != "POST" || (path != "/lookup" && path != "/update") {
		http.Error(w, `this server only supports queries of the POST /lookup or POST /update`, http.StatusNotFound)
		return
	}
	pf := &proto.LookupProof{}
	var err error
	ctx := context.Background()
	if path == "/lookup" {
		pf, err = h.doLookup(r.Body, ctx)
		if err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
	} else if path == "/update" {
		pf, err = h.doUpdate(r.Body, ctx)
		if err != nil {
			status := http.StatusBadRequest
			if h.IsAuthExpired(err) {
				status = http.StatusUnauthorized
			}
			http.Error(w, err.Error(), status)
			return
		}
	}
	// preserve the original field name
	marshaler := jsonpb.Marshaler{OrigName: true}
	err = marshaler.Marshal(w, pf)
	if err != nil {
		http.Error(w, `Internal server error`, http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	return
}
开发者ID:yahoo,项目名称:coname,代码行数:79,代码来源:httpfront.go


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