本文整理汇总了Golang中github.com/keybase/go-jsonw.Unmarshal函数的典型用法代码示例。如果您正苦于以下问题:Golang Unmarshal函数的具体用法?Golang Unmarshal怎么用?Golang Unmarshal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Unmarshal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestListTrackingJSON
func TestListTrackingJSON(t *testing.T) {
tc := SetupEngineTest(t, "track")
defer tc.Cleanup()
fu := CreateAndSignupFakeUser(tc, "track")
fu.LoginOrBust(tc)
trackAlice(tc, fu)
defer untrackAlice(tc, fu)
arg := ListTrackingEngineArg{JSON: true, Verbose: true}
eng := NewListTrackingEngine(&arg, tc.G)
ctx := Context{}
err := RunEngine(eng, &ctx)
if err != nil {
t.Fatal("Error in ListTrackingEngine:", err)
}
jw, err := jsonw.Unmarshal([]byte(eng.JSONResult()))
if err != nil {
t.Fatal(err)
}
pgpKeys := jw.AtIndex(0).AtPath("body.track.pgp_keys")
n, err := pgpKeys.Len()
if err != nil {
t.Fatal(err)
}
if n != 1 {
t.Errorf("num pgp_keys: %d, expected 1", n)
}
}
示例2: SetValue
func (h ConfigHandler) SetValue(_ context.Context, arg keybase1.SetValueArg) (err error) {
w := h.G().Env.GetConfigWriter()
if arg.Path == "users" {
err = fmt.Errorf("The field 'users' cannot be edited for fear of config corruption")
return err
}
switch {
case arg.Value.IsNull:
w.SetNullAtPath(arg.Path)
case arg.Value.S != nil:
w.SetStringAtPath(arg.Path, *arg.Value.S)
case arg.Value.I != nil:
w.SetIntAtPath(arg.Path, *arg.Value.I)
case arg.Value.B != nil:
w.SetBoolAtPath(arg.Path, *arg.Value.B)
case arg.Value.O != nil:
var jw *jsonw.Wrapper
jw, err = jsonw.Unmarshal([]byte(*arg.Value.O))
if err == nil {
err = w.SetWrapperAtPath(arg.Path, jw)
}
default:
err = fmt.Errorf("Bad type for setting a value")
}
if err == nil {
h.G().ConfigReload()
}
return err
}
示例3: CounterSign
// CounterSign implements CounterSign in kex2.Provisioner.
func (e *Kex2Provisioner) CounterSign(input keybase1.HelloRes) (sig []byte, err error) {
e.G().Log.Debug("+ CounterSign()")
defer func() { e.G().Log.Debug("- CounterSign() -> %s", libkb.ErrToOk(err)) }()
jw, err := jsonw.Unmarshal([]byte(input))
if err != nil {
return nil, err
}
// check the reverse signature
if err = e.checkReverseSig(jw); err != nil {
e.G().Log.Debug("provisioner failed to verify reverse sig: %s", err)
return nil, err
}
e.G().Log.Debug("provisioner verified reverse sig")
// remember some device information for ProvisionUI.ProvisionerSuccess()
if err = e.rememberDeviceInfo(jw); err != nil {
return nil, err
}
// sign the whole thing with provisioner's signing key
s, _, _, err := libkb.SignJSON(jw, e.signingKey)
if err != nil {
return nil, err
}
return []byte(s), nil
}
示例4: Lookup
func (j *JSONLocalDb) Lookup(id DbKey) (*jsonw.Wrapper, error) {
bytes, found, err := j.engine.Lookup(id)
var ret *jsonw.Wrapper
if found {
ret, err = jsonw.Unmarshal(bytes)
}
return ret, err
}
示例5: VerifyPath
func (path PathSteps) VerifyPath(curr NodeHash, uidS string) (juser *jsonw.Wrapper, err error) {
bpath := uidS
pos := 0
lastTyp := 0
for i, step := range path {
payload := step.node
if !curr.Check(payload) {
err = fmt.Errorf("Hash mismatch at level=%d", i)
break
}
var jw *jsonw.Wrapper
jw, err = jsonw.Unmarshal([]byte(payload))
if err != nil {
err = fmt.Errorf("Can't parse JSON at level=%d: %s", i, err)
break
}
plen := len(step.prefix)
epos := pos + plen
if bpath[pos:epos] != step.prefix {
err = fmt.Errorf("Path mismatch at level %d: %s != %s",
i, bpath[pos:epos], step.prefix)
break
}
pos = epos
lastTyp, err = jw.AtKey("type").GetInt()
if err != nil {
err = fmt.Errorf("At level %d, failed to get a valid 'type'", i)
break
}
if lastTyp == MerkleTreeNode {
if plen == 0 {
err = fmt.Errorf("Empty prefix len at level=%d", i)
return
}
curr, err = GetNodeHash(jw.AtKey("tab").AtKey(step.prefix))
if err != nil {
err = MerkleNotFoundError{uidS, err.Error()}
break
}
juser = nil
} else {
juser = jw.AtKey("tab").AtKey(uidS)
}
}
if err == nil && juser == nil {
err = MerkleNotFoundError{uidS, "tree path didn't end in a leaf"}
}
return
}
示例6: handleShowTrackerPopupCreate
func (h IdentifyUIHandler) handleShowTrackerPopupCreate(ctx context.Context, cli gregor1.IncomingInterface,
item gregor.Item) error {
h.G().Log.Debug("handleShowTrackerPopupCreate: %+v", item)
if item.Body() == nil {
return errors.New("gregor handler for show_tracker_popup: nil message body")
}
body, err := jsonw.Unmarshal(item.Body().Bytes())
if err != nil {
h.G().Log.Debug("body failed to unmarshal", err)
return err
}
uidString, err := body.AtPath("uid").GetString()
if err != nil {
h.G().Log.Debug("failed to extract uid", err)
return err
}
uid, err := keybase1.UIDFromString(uidString)
if err != nil {
h.G().Log.Debug("failed to convert UID from string", err)
return err
}
identifyUI, err := h.G().UIRouter.GetIdentifyUI()
if err != nil {
h.G().Log.Debug("failed to get IdentifyUI", err)
return err
}
if identifyUI == nil {
h.G().Log.Debug("got nil IdentifyUI")
return errors.New("got nil IdentifyUI")
}
secretUI, err := h.G().UIRouter.GetSecretUI(0)
if err != nil {
h.G().Log.Debug("failed to get SecretUI", err)
return err
}
if secretUI == nil {
h.G().Log.Debug("got nil SecretUI")
return errors.New("got nil SecretUI")
}
engineContext := engine.Context{
IdentifyUI: identifyUI,
SecretUI: secretUI,
}
identifyReason := keybase1.IdentifyReason{
Type: keybase1.IdentifyReasonType_TRACK,
// TODO: text here?
}
identifyArg := keybase1.Identify2Arg{Uid: uid, Reason: identifyReason}
identifyEng := engine.NewIdentify2WithUID(h.G(), &identifyArg)
identifyEng.SetResponsibleGregorItem(item)
return identifyEng.Run(&engineContext)
}
示例7: importTrackingLink
func importTrackingLink(t *testing.T, g *libkb.GlobalContext) *libkb.TrackChainLink {
jw, err := jsonw.Unmarshal([]byte(trackingServerReply))
if err != nil {
t.Fatal(err)
}
cl, err := libkb.ImportLinkFromServer(g, nil, jw, trackingUID)
if err != nil {
t.Fatal(err)
}
gl := libkb.GenericChainLink{ChainLink: cl}
tcl, err := libkb.ParseTrackChainLink(gl)
if err != nil {
t.Fatal(err)
}
return tcl
}
示例8: handleShowTrackerPopupDismiss
func (h IdentifyUIHandler) handleShowTrackerPopupDismiss(ctx context.Context, cli gregor1.IncomingInterface,
item gregor.Item) error {
h.G().Log.Debug("handleShowTrackerPopupDismiss: %+v", item)
if item.Body() == nil {
return errors.New("gregor dismissal for show_tracker_popup: nil message body")
}
body, err := jsonw.Unmarshal(item.Body().Bytes())
if err != nil {
h.G().Log.Debug("body failed to unmarshal", err)
return err
}
uidString, err := body.AtPath("uid").GetString()
if err != nil {
h.G().Log.Debug("failed to extract uid", err)
return err
}
uid, err := keybase1.UIDFromString(uidString)
if err != nil {
h.G().Log.Debug("failed to convert UID from string", err)
return err
}
user, err := libkb.LoadUser(libkb.NewLoadUserByUIDArg(h.G(), uid))
if err != nil {
h.G().Log.Debug("failed to load user from UID", err)
return err
}
identifyUI, err := h.G().UIRouter.GetIdentifyUI()
if err != nil {
h.G().Log.Debug("failed to get IdentifyUI", err)
return err
}
if identifyUI == nil {
h.G().Log.Debug("got nil IdentifyUI")
return errors.New("got nil IdentifyUI")
}
reason := keybase1.DismissReason{
Type: keybase1.DismissReasonType_HANDLED_ELSEWHERE,
}
identifyUI.Dismiss(user.GetName(), reason)
return nil
}
示例9: NewMerkleRootFromJSON
func NewMerkleRootFromJSON(jw *jsonw.Wrapper, g *GlobalContext) (ret *MerkleRoot, err error) {
var seqno int64
var sigs *jsonw.Wrapper
var payloadJSONString string
var pj *jsonw.Wrapper
var fp PGPFingerprint
var rh, lurh NodeHash
var ctime int64
if sigs, err = jw.AtKey("sigs").ToDictionary(); err != nil {
return
}
if payloadJSONString, err = jw.AtKey("payload_json").GetString(); err != nil {
return
}
if pj, err = jsonw.Unmarshal([]byte(payloadJSONString)); err != nil {
return
}
GetPGPFingerprintVoid(pj.AtPath("body.key.fingerprint"), &fp, &err)
pj.AtPath("body.seqno").GetInt64Void(&seqno, &err)
GetNodeHashVoid(pj.AtPath("body.root"), &rh, &err)
lurh, _ = GetNodeHash(pj.AtPath("body.legacy_uid_root"))
pj.AtKey("ctime").GetInt64Void(&ctime, &err)
if err != nil {
return
}
ret = &MerkleRoot{
seqno: Seqno(seqno),
pgpFingerprint: fp,
sigs: sigs,
payloadJSONString: payloadJSONString,
payloadJSON: pj,
rootHash: rh,
legacyUIDRootHash: lurh,
ctime: ctime,
Contextified: NewContextified(g),
}
return
}
示例10: Post
func (s *sendInvitationMock) Post(arg APIArg) (*APIRes, error) {
if _, err := s.APIArgRecorder.Post(arg); err != nil {
return nil, err
}
jw, err := jsonw.Unmarshal([]byte(`{"status":{"code":0,"name":"OK"},"short_code":"clip outside broccoli culture","invitation_id":"2b25175f6da1d9155f23800d","csrf_token":"lgHZIDBlNjRhNDBhOTQ3ZWYyMTMxOWQ4MzM1Y2M4YjQ1YjE5zlcVNMHOAAFRgMDEIFyHOIg/AetihKRvVMNT2NoBNNG1QoCVxtDfzEK7/rdF"}`))
if err != nil {
return nil, err
}
return &APIRes{
Status: jw.AtKey("status"),
Body: jw,
HTTPStatus: 200,
AppStatus: &AppStatus{
Code: SCOk,
Name: "OK",
Desc: "Ok",
},
}, nil
}
示例11: HandleHello
// HandleHello implements HandleHello in kex2.Provisionee.
func (e *Kex2Provisionee) HandleHello(harg keybase1.HelloArg) (res keybase1.HelloRes, err error) {
e.G().Log.Debug("+ HandleHello()")
defer func() { e.G().Log.Debug("- HandleHello() -> %s", libkb.ErrToOk(err)) }()
// save parts of the hello arg for later:
e.uid = harg.Uid
e.sessionToken = harg.Token
e.csrfToken = harg.Csrf
e.pps = harg.Pps
jw, err := jsonw.Unmarshal([]byte(harg.SigBody))
if err != nil {
return res, err
}
// need the username later:
e.username, err = jw.AtPath("body.key.username").GetString()
if err != nil {
return res, err
}
e.eddsa, err = libkb.GenerateNaclSigningKeyPair()
if err != nil {
return res, err
}
if err = e.addDeviceSibkey(jw); err != nil {
return res, err
}
if err = e.reverseSig(jw); err != nil {
return res, err
}
out, err := jw.Marshal()
if err != nil {
return res, err
}
return keybase1.HelloRes(out), err
}
示例12: TestAPIServerPostJSON
func TestAPIServerPostJSON(t *testing.T) {
tc := libkb.SetupTest(t, "apiserver", 2)
defer tc.Cleanup()
tc.G.SetService()
_, err := kbtest.CreateAndSignupFakeUser("apivr", tc.G)
if err != nil {
t.Fatal(err)
}
jsonPayload := []keybase1.StringKVPair{
{Key: "sigs", Value: "[]"},
}
arg := keybase1.PostJSONArg{
Endpoint: "key/multi",
JSONPayload: jsonPayload,
}
handler := NewAPIServerHandler(nil, tc.G)
res, err := handler.doPostJSON(arg)
if err != nil {
t.Fatal(err)
}
jw, err := jsonw.Unmarshal([]byte(res.Body))
if err != nil {
t.Fatal(err)
}
namew := jw.AtKey("status").AtKey("name")
name, err := namew.GetString()
if err != nil {
t.Fatal(err)
}
if name != "OK" {
t.Fatalf("wrong name returned: %s != %s", name, "OK")
}
}
示例13: TestAPIServerGet
func TestAPIServerGet(t *testing.T) {
tc := libkb.SetupTest(t, "apiserver", 2)
defer tc.Cleanup()
tc.G.SetService()
_, err := kbtest.CreateAndSignupFakeUser("apivr", tc.G)
if err != nil {
t.Fatal(err)
}
harg := []keybase1.StringKVPair{
{Key: "username", Value: "t_alice"},
{Key: "fields", Value: "basics"},
}
arg := keybase1.GetArg{
Endpoint: "user/lookup",
Args: harg,
}
handler := NewAPIServerHandler(nil, tc.G)
res, err := handler.doGet(arg)
if err != nil {
t.Fatal(err)
}
jw, err := jsonw.Unmarshal([]byte(res.Body))
if err != nil {
t.Fatal(err)
}
usernamew := jw.AtKey("them").AtKey("basics").AtKey("username")
username, err := usernamew.GetString()
if err != nil {
t.Fatal(err)
}
if username != "t_alice" {
t.Fatalf("wrong username returned: %s != %s", username, "t_alice")
}
}
示例14: kbfsFavorites
func (g *gregorHandler) kbfsFavorites(ctx context.Context, m gregor.OutOfBandMessage) error {
if m.Body() == nil {
return errors.New("gregor handler for kbfs.favorites: nil message body")
}
body, err := jsonw.Unmarshal(m.Body().Bytes())
if err != nil {
return err
}
action, err := body.AtPath("action").GetString()
if err != nil {
return err
}
switch action {
case "create", "delete":
return g.notifyFavoritesChanged(ctx, m.UID())
default:
return fmt.Errorf("unhandled kbfs.favorites action %q", action)
}
}
示例15: decodeSig
func (e *Kex2Provisionee) decodeSig(sig []byte) (*decodedSig, error) {
body, err := base64.StdEncoding.DecodeString(string(sig))
if err != nil {
return nil, err
}
packet, err := libkb.DecodePacket(body)
if err != nil {
return nil, err
}
naclSig, ok := packet.Body.(*libkb.NaclSigInfo)
if !ok {
return nil, libkb.UnmarshalError{T: "Nacl signature"}
}
jw, err := jsonw.Unmarshal(naclSig.Payload)
if err != nil {
return nil, err
}
res := decodedSig{
sigID: libkb.ComputeSigIDFromSigBody(body),
linkID: libkb.ComputeLinkID(naclSig.Payload),
}
res.seqno, err = jw.AtKey("seqno").GetInt()
if err != nil {
return nil, err
}
seldestKID, err := jw.AtPath("body.key.eldest_kid").GetString()
if err != nil {
return nil, err
}
res.eldestKID = keybase1.KIDFromString(seldestKID)
ssigningKID, err := jw.AtPath("body.key.kid").GetString()
if err != nil {
return nil, err
}
res.signingKID = keybase1.KIDFromString(ssigningKID)
return &res, nil
}