本文整理匯總了Golang中github.com/keybase/go-jsonw.Wrapper.Len方法的典型用法代碼示例。如果您正苦於以下問題:Golang Wrapper.Len方法的具體用法?Golang Wrapper.Len怎麽用?Golang Wrapper.Len使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/keybase/go-jsonw.Wrapper
的用法示例。
在下文中一共展示了Wrapper.Len方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseV2
func parseV2(jw *jsonw.Wrapper) (*MerkleUserLeaf, error) {
user := MerkleUserLeaf{}
l, err := jw.Len()
if err != nil {
return nil, err
}
if l < 2 {
return nil, fmt.Errorf("No public chain.")
}
user.public, err = parseTriple(jw.AtIndex(1))
if err != nil {
return nil, err
}
if l >= 3 {
user.private, err = parseTriple(jw.AtIndex(2))
if err != nil {
return nil, err
}
}
if l >= 4 && !jw.AtIndex(3).IsNil() {
eldest, err := GetKID(jw.AtIndex(3))
if err != nil {
return nil, err
}
user.eldest = eldest
}
return &user, nil
}
示例2: resolveURLViaServerLookup
func (r *Resolver) resolveURLViaServerLookup(au AssertionURL, input string, withBody bool) (res ResolveResult) {
var key, val string
var ares *APIRes
var l int
if au.IsKeybase() {
res.kbUsername = au.GetValue()
}
if key, val, res.err = au.ToLookup(); res.err != nil {
return
}
ha := HTTPArgsFromKeyValuePair(key, S{val})
ha.Add("multi", I{1})
fields := "basics"
if withBody {
fields += ",public_keys,pictures"
}
ha.Add("fields", S{fields})
ares, res.err = r.G().API.Get(APIArg{
Endpoint: "user/lookup",
NeedSession: false,
Args: ha,
})
if res.err != nil {
return
}
var them *jsonw.Wrapper
if them, res.err = ares.Body.AtKey("them").ToArray(); res.err != nil {
return
}
if l, res.err = them.Len(); res.err != nil {
return
}
if l == 0 {
res.err = ResolutionError{Input: input, Msg: "No resolution found"}
} else if l > 1 {
res.err = ResolutionError{Input: input, Msg: "Identify is ambiguous"}
} else {
res.body = them.AtIndex(0)
res.uid, res.err = GetUID(res.body.AtKey("id"))
}
return
}
示例3: resolveUsername
func resolveUsername(au AssertionURL) (res ResolveResult) {
var key, val string
var ares *APIRes
var l int
if au.IsKeybase() {
res.kbUsername = au.GetValue()
}
if key, val, res.err = au.ToLookup(); res.err != nil {
return
}
ha := HTTPArgsFromKeyValuePair(key, S{val})
ha.Add("multi", I{1})
ares, res.err = G.API.Get(APIArg{
Endpoint: "user/lookup",
NeedSession: false,
Args: ha,
})
if res.err != nil {
return
}
var them *jsonw.Wrapper
if them, res.err = ares.Body.AtKey("them").ToArray(); res.err != nil {
return
}
if l, res.err = them.Len(); res.err != nil {
return
}
if l == 0 {
res.err = fmt.Errorf("No resolution found for %s", au)
} else if l > 1 {
res.err = fmt.Errorf("Identity '%s' is ambiguous", au)
} else {
res.body = them.AtIndex(0)
res.uid, res.err = GetUID(res.body.AtKey("id"))
}
return
}
示例4: getStringArray
func (f JSONConfigFile) getStringArray(v *jsonw.Wrapper) []string {
n, err := v.Len()
if err != nil {
return nil
}
if n == 0 {
return nil
}
ret := make([]string, n)
for i := 0; i < n; i++ {
s, err := v.AtIndex(i).GetString()
if err != nil {
return nil
}
ret[i] = s
}
return ret
}
示例5: parseMerkleUserLeaf
func parseMerkleUserLeaf(jw *jsonw.Wrapper, g *GlobalContext) (user *MerkleUserLeaf, err error) {
g.Log.Debug("+ ParsingMerkleUserLeaf")
if jw == nil {
g.Log.Debug("| empty leaf found; user wasn't in tree")
user = &MerkleUserLeaf{}
return
}
l, err := jw.Len()
if err != nil {
return
}
if l < 2 {
err = fmt.Errorf("Expected an array of length 2 or more")
return
}
v, err := jw.AtIndex(0).GetInt()
if err != nil {
return
}
// We messed up and didn't version the initial leafs of the tree
if _, e2 := jw.AtIndex(1).GetString(); e2 == nil {
v = 1
}
switch v {
case 1:
user, err = parseV1(jw)
case 2:
user, err = parseV2(jw)
default:
err = fmt.Errorf("Unexpected version: %d", v)
}
g.Log.Debug("- ParsingMerkleUserLeaf -> %v", ErrToOk(err))
return
}
示例6: parseTriple
func parseTriple(jw *jsonw.Wrapper) (*MerkleTriple, error) {
if jw.IsNil() {
return nil, nil
}
l, err := jw.Len()
if err != nil {
return nil, err
}
if l == 0 {
return nil, nil
}
if l == 1 {
return nil, fmt.Errorf("Bad merkle 'triple', with < 2 values")
}
if l > 3 {
return nil, fmt.Errorf("Bad merkle triple, with > 3 values")
}
seqno, err := jw.AtIndex(0).GetInt()
if err != nil {
return nil, err
}
li, err := GetLinkID(jw.AtIndex(1))
if err != nil {
return nil, err
}
var si keybase1.SigID
if l == 3 {
si, err = GetSigID(jw.AtIndex(2), false)
if err != nil {
return nil, err
}
}
return &MerkleTriple{Seqno(seqno), li, si}, nil
}
示例7: importPathFromJSON
func importPathFromJSON(jw *jsonw.Wrapper) (out []*PathStep, err error) {
if jw.IsNil() {
return
}
var path *jsonw.Wrapper
if path, err = jw.ToArray(); err != nil {
return
}
var l int
if l, err = path.Len(); err != nil {
return
}
for i := 0; i < l; i++ {
var step *PathStep
if step, err = pathStepFromJSON(path.AtIndex(i)); err != nil {
return
}
out = append(out, step)
}
return
}
示例8: resolveURLViaServerLookup
func (r *Resolver) resolveURLViaServerLookup(au AssertionURL, input string, withBody bool) (res ResolveResult) {
defer r.G().Trace(fmt.Sprintf("resolveURLViaServerLookup(input = %q)", input), func() error { return res.err })()
var key, val string
var ares *APIRes
var l int
if au.IsKeybase() {
res.queriedKbUsername = au.GetValue()
}
if key, val, res.err = au.ToLookup(); res.err != nil {
return
}
ha := HTTPArgsFromKeyValuePair(key, S{val})
ha.Add("multi", I{1})
fields := "basics"
if withBody {
fields += ",public_keys,pictures"
}
ha.Add("fields", S{fields})
ares, res.err = r.G().API.Get(APIArg{
Endpoint: "user/lookup",
NeedSession: false,
Args: ha,
AppStatusCodes: []int{SCOk, SCNotFound},
Contextified: NewContextified(r.G()),
})
if res.err != nil {
r.G().Log.Debug("API user/lookup %q error: %s", input, res.err)
return
}
if ares.AppStatus.Code == SCNotFound {
r.G().Log.Debug("API user/lookup %q not found", input)
res.err = NotFoundError{}
return
}
var them *jsonw.Wrapper
if them, res.err = ares.Body.AtKey("them").ToArray(); res.err != nil {
return
}
if l, res.err = them.Len(); res.err != nil {
return
}
if l == 0 {
res.err = ResolutionError{Input: input, Msg: "No resolution found"}
} else if l > 1 {
res.err = ResolutionError{Input: input, Msg: "Identify is ambiguous"}
} else {
res.body = them.AtIndex(0)
res.uid, res.err = GetUID(res.body.AtKey("id"))
if res.err == nil {
res.resolvedKbUsername, res.err = res.body.AtPath("basics.username").GetString()
}
}
return
}