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


Golang Macaroon.UnmarshalJSON方法代碼示例

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


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

示例1: Auth

func Auth(h MacrHandler) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// This is fast, if it's not timed out
		macHdr := r.Header.Get("Macaroon")

		// These will have to talk to another authority to authorize.
		// TODO configurable timeout
		authHdr := r.Header.Get("Authorization")
		// keyHdr := r.Header.Get("Keystone")
		// etc..

		switch {
		case macHdr != "":
			mac := new(macaroon.Macaroon)
			err := mac.UnmarshalJSON([]byte(macHdr))
			if err != nil {
				w.Write([]byte("error deserializing Macaroon"))
				return
			}
			// TODO check for timeout, add discharge to Header
			// TODO check for third party auth
			h(w, r, mac)
		case authHdr != "":
		default:
			w.Write([]byte("no auth supplied"))
			return
		}
	}
}
開發者ID:rdallman,項目名稱:toy-macaroon,代碼行數:29,代碼來源:server.go

示例2: TestBinaryMarshalingAgainstLibmacaroon

func (*macaroonSuite) TestBinaryMarshalingAgainstLibmacaroon(c *gc.C) {
	// Test that a libmacaroon marshalled macaroon can be correctly unmarshaled
	data, err := base64.StdEncoding.DecodeString(
		"MDAxN2xvY2F0aW9uIHNvbWV3aGVyZQowMDEyaWRlbnRpZmllciBpZAowMDEzY2lkIGlkZW50aWZpZXIKMDA1MXZpZCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC4i9QwCgbL/wZGFvLQpsyhLOv0v6VjIo2KJv5miz+7krqCpt5EhmrL8pYO9xrhT80KMDAxM2NsIHRoaXJkIHBhcnR5CjAwMmZzaWduYXR1cmUg3BXkIDX0giAPPrgkDLbiMGYy/zsC2qPb4jU4G/dohkAK")
	c.Assert(err, gc.IsNil)
	var m0 macaroon.Macaroon
	err = m0.UnmarshalBinary(data)
	c.Assert(err, gc.IsNil)
	jsonData := []byte(`{"caveats":[{"cid":"identifier\n","vid":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuIvUMAoGy/8GRhby0KbMoSzr9L+lYyKNiib+Zos/u5K6gqbeRIZqy/KWDvca4U/NCg==","cl":"third party\n"}],"location":"somewhere\n","identifier":"id\n","signature":"dc15e42035f482200f3eb8240cb6e2306632ff3b02daa3dbe235381bf76886400a"}`)
	var m1 macaroon.Macaroon
	err = m1.UnmarshalJSON(jsonData)
	c.Assert(err, gc.IsNil)
	assertEqualMacaroons(c, &m0, &m1)
}
開發者ID:jrwren,項目名稱:macaroon-bakery,代碼行數:14,代碼來源:macaroon_test.go

示例3: BenchmarkUnmarshalJSON

func BenchmarkUnmarshalJSON(b *testing.B) {
	rootKey := randomBytes(24)
	id := base64.StdEncoding.EncodeToString(randomBytes(100))
	loc := base64.StdEncoding.EncodeToString(randomBytes(40))
	m := MustNew(rootKey, id, loc)
	data, err := m.MarshalJSON()
	if err != nil {
		b.Fatalf("cannot marshal JSON: %v", err)
	}
	for i := b.N - 1; i >= 0; i-- {
		var m macaroon.Macaroon
		err := m.UnmarshalJSON(data)
		if err != nil {
			b.Fatalf("cannot unmarshal JSON: %v", err)
		}
	}
}
開發者ID:jrwren,項目名稱:macaroon-bakery,代碼行數:17,代碼來源:bench_test.go


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