From 352db24f4642f0201fbc99f1688daabfc0e8ffaf Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 29 Nov 2011 18:14:34 -0800 Subject: [PATCH] index: move more key building into keyType Change-Id: I2928f4ba345ebe11a3d6c9f63a1a381cb13bfb28 --- lib/go/camli/index/keys.go | 37 ++++++++++++++++++++++++++++------- lib/go/camli/index/receive.go | 3 +-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/go/camli/index/keys.go b/lib/go/camli/index/keys.go index bc86058b5..39964aedf 100644 --- a/lib/go/camli/index/keys.go +++ b/lib/go/camli/index/keys.go @@ -27,18 +27,41 @@ type keyType struct { } func (k *keyType) Prefix(args ...interface{}) string { + return k.build(true, args...) +} + +func (k *keyType) Key(args ...interface{}) string { + return k.build(false, args...) +} + +func (k *keyType) build(finalPipe bool, args ...interface{}) string { var buf bytes.Buffer buf.WriteString(k.name) - for _, arg := range args { + for i, arg := range args { buf.WriteString("|") - // TODO(bradfitz): verify the type matches - if s, ok := arg.(string); ok { - buf.WriteString(s) - } else { - buf.WriteString(arg.(fmt.Stringer).String()) + switch k.parts[i].typ { + case typeReverseTime: + s, ok := arg.(string) + if !ok { + s = arg.(fmt.Stringer).String() + } + const example = "2011-01-23T05:23:12" + if len(s) < len(example) || s[4] != '-' && s[10] != 'T' { + panic("doesn't look like a time: " + s) + } + buf.WriteString(reverseTimeString(s)) + default: + // TODO(bradfitz): reverse time and such + if s, ok := arg.(string); ok { + buf.WriteString(s) + } else { + buf.WriteString(arg.(fmt.Stringer).String()) + } } } - buf.WriteString("|") + if finalPipe { + buf.WriteString("|") + } return buf.String() } diff --git a/lib/go/camli/index/receive.go b/lib/go/camli/index/receive.go index 3346a1dc2..3b57dfc28 100644 --- a/lib/go/camli/index/receive.go +++ b/lib/go/camli/index/receive.go @@ -121,8 +121,7 @@ func (ix *Index) populateClaim(br *blobref.BlobRef, ss *schema.Superset, sniffer bm.Set("signerkeyid:"+vr.CamliSigner.String(), verifiedKeyId) - // TODO(bradfitz): use keyRecentPermanode here instead of pipes() with "recpn". - recentKey := pipes("recpn", verifiedKeyId, reverseTimeString(ss.ClaimDate), br) + recentKey := keyRecentPermanode.Key(verifiedKeyId, ss.ClaimDate, br) bm.Set(recentKey, pnbr.String()) claimKey := pipes("claim", pnbr, verifiedKeyId, ss.ClaimDate, br)