本文整理匯總了Golang中camlistore/org/pkg/blob.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: kvDeleted
func kvDeleted(k string) (c camtypes.Claim, ok bool) {
// TODO(bradfitz): garbage
keyPart := strings.Split(k, "|")
if len(keyPart) != 4 {
return
}
if keyPart[0] != "deleted" {
return
}
target, ok := blob.Parse(keyPart[1])
if !ok {
return
}
claimRef, ok := blob.Parse(keyPart[3])
if !ok {
return
}
date, err := time.Parse(time.RFC3339, unreverseTimeString(keyPart[2]))
if err != nil {
return
}
return camtypes.Claim{
BlobRef: claimRef,
Target: target,
Date: date,
Type: string(schema.DeleteClaim),
}, true
}
示例2: EnumerateBlobs
func (sto *s3Storage) EnumerateBlobs(ctx *context.Context, dest chan<- blob.SizedRef, after string, limit int) (err error) {
defer close(dest)
if faultEnumerate.FailErr(&err) {
return
}
startAt := after
if _, ok := blob.Parse(after); ok {
startAt = nextStr(after)
}
objs, err := sto.s3Client.ListBucket(sto.bucket, startAt, limit)
if err != nil {
log.Printf("s3 ListBucket: %v", err)
return err
}
for _, obj := range objs {
if obj.Key == after {
continue
}
br, ok := blob.Parse(obj.Key)
if !ok {
continue
}
select {
case dest <- blob.SizedRef{Ref: br, Size: uint32(obj.Size)}:
case <-ctx.Done():
return context.ErrCanceled
}
}
return nil
}
示例3: EnumerateBlobs
func (sto *s3Storage) EnumerateBlobs(ctx context.Context, dest chan<- blob.SizedRef, after string, limit int) (err error) {
defer close(dest)
if faultEnumerate.FailErr(&err) {
return
}
startAt := after
if _, ok := blob.Parse(after); ok {
startAt = nextStr(after)
}
objs, err := sto.s3Client.ListBucket(sto.bucket, sto.dirPrefix+startAt, limit)
if err != nil {
log.Printf("s3 ListBucket: %v", err)
return err
}
for _, obj := range objs {
dir, file := path.Split(obj.Key)
if dir != sto.dirPrefix {
continue
}
if file == after {
continue
}
br, ok := blob.Parse(file)
if !ok {
// TODO(mpl): I've noticed that on GCS we error out for this case. Do the same here ?
continue
}
select {
case dest <- blob.SizedRef{Ref: br, Size: uint32(obj.Size)}:
case <-ctx.Done():
return ctx.Err()
}
}
return nil
}
示例4: kvEdgeBackward
func kvEdgeBackward(k, v string) (edge *camtypes.Edge, ok bool) {
// TODO(bradfitz): garbage
keyPart := strings.Split(k, "|")
valPart := strings.Split(v, "|")
if len(keyPart) != 4 || len(valPart) != 2 {
// TODO(mpl): use glog
log.Printf("bogus keyEdgeBackward index entry: %q = %q", k, v)
return
}
if keyPart[0] != "edgeback" {
return
}
parentRef, ok := blob.Parse(keyPart[2])
if !ok {
log.Printf("bogus parent in keyEdgeBackward index entry: %q", keyPart[2])
return
}
blobRef, ok := blob.Parse(keyPart[3])
if !ok {
log.Printf("bogus blobref in keyEdgeBackward index entry: %q", keyPart[3])
return
}
return &camtypes.Edge{
From: parentRef,
FromType: valPart[0],
FromTitle: valPart[1],
BlobRef: blobRef,
}, true
}
示例5: kvSignerAttrValue
func kvSignerAttrValue(k, v string) (c camtypes.Claim, ok bool) {
// TODO(bradfitz): garbage
keyPart := strings.Split(k, "|")
valPart := strings.Split(v, "|")
if len(keyPart) != 6 || len(valPart) != 1 {
// TODO(mpl): use glog
log.Printf("bogus keySignerAttrValue index entry: %q = %q", k, v)
return
}
if keyPart[0] != "signerattrvalue" {
return
}
date, err := time.Parse(time.RFC3339, unreverseTimeString(keyPart[4]))
if err != nil {
log.Printf("bogus time in keySignerAttrValue index entry: %q", keyPart[4])
return
}
claimRef, ok := blob.Parse(keyPart[5])
if !ok {
log.Printf("bogus claim in keySignerAttrValue index entry: %q", keyPart[5])
return
}
permaNode, ok := blob.Parse(valPart[0])
if !ok {
log.Printf("bogus permanode in keySignerAttrValue index entry: %q", valPart[0])
return
}
return camtypes.Claim{
BlobRef: claimRef,
Permanode: permaNode,
Date: date,
Attr: urld(keyPart[2]),
Value: urld(keyPart[3]),
}, true
}
示例6: PathsOfSignerTarget
func (x *Index) PathsOfSignerTarget(signer, target blob.Ref) (paths []*search.Path, err error) {
paths = []*search.Path{}
keyId, err := x.keyId(signer)
if err != nil {
if err == ErrNotFound {
err = nil
}
return
}
mostRecent := make(map[string]*search.Path)
maxClaimDates := make(map[string]string)
it := x.queryPrefix(keyPathBackward, keyId, target)
defer closeIterator(it, &err)
for it.Next() {
keyPart := strings.Split(it.Key(), "|")[1:]
valPart := strings.Split(it.Value(), "|")
if len(keyPart) < 3 || len(valPart) < 4 {
continue
}
claimRef, ok := blob.Parse(keyPart[2])
if !ok {
continue
}
baseRef, ok := blob.Parse(valPart[1])
if !ok {
continue
}
claimDate := valPart[0]
active := valPart[2]
suffix := urld(valPart[3])
key := baseRef.String() + "/" + suffix
if claimDate > maxClaimDates[key] {
maxClaimDates[key] = claimDate
if active == "Y" {
mostRecent[key] = &search.Path{
Claim: claimRef,
ClaimDate: claimDate,
Base: baseRef,
Suffix: suffix,
Target: target,
}
} else {
delete(mostRecent, key)
}
}
}
for _, v := range mostRecent {
paths = append(paths, v)
}
return paths, nil
}
示例7: PathsLookup
func (x *Index) PathsLookup(signer, base blob.Ref, suffix string) (paths []*search.Path, err error) {
paths = []*search.Path{}
keyId, err := x.keyId(signer)
if err != nil {
if err == ErrNotFound {
err = nil
}
return
}
it := x.queryPrefix(keyPathForward, keyId, base, suffix)
defer closeIterator(it, &err)
for it.Next() {
keyPart := strings.Split(it.Key(), "|")[1:]
valPart := strings.Split(it.Value(), "|")
if len(keyPart) < 5 || len(valPart) < 2 {
continue
}
claimRef, ok := blob.Parse(keyPart[4])
if !ok {
continue
}
baseRef, ok := blob.Parse(keyPart[1])
if !ok {
continue
}
claimDate := unreverseTimeString(keyPart[3])
suffix := urld(keyPart[2])
target, ok := blob.Parse(valPart[1])
if !ok {
continue
}
// TODO(bradfitz): investigate what's up with deleted
// forward path claims here. Needs docs with the
// interface too, and tests.
active := valPart[0]
_ = active
path := &search.Path{
Claim: claimRef,
ClaimDate: claimDate,
Base: baseRef,
Suffix: suffix,
Target: target,
}
paths = append(paths, path)
}
return
}
示例8: serveFiles
func (sh *Handler) serveFiles(rw http.ResponseWriter, req *http.Request) {
ret := jsonMap()
defer httputil.ReturnJSON(rw, ret)
br, ok := blob.Parse(req.FormValue("wholedigest"))
if !ok {
ret["error"] = "Missing or invalid 'wholedigest' param"
ret["errorType"] = "input"
return
}
files, err := sh.index.ExistingFileSchemas(br)
if err != nil {
ret["error"] = err.Error()
ret["errorType"] = "server"
return
}
strList := []string{}
for _, br := range files {
strList = append(strList, br.String())
}
ret["files"] = strList
return
}
示例9: RunCommand
func (c *shareCmd) RunCommand(args []string) error {
unsigned := schema.NewShareRef(schema.ShareHaveRef, c.transitive)
if c.search != "" {
if len(args) != 0 {
return cmdmain.UsageError("when using the -search flag, share takes zero arguments")
}
var q search.SearchQuery
if err := json.Unmarshal([]byte(c.search), &q); err != nil {
return cmdmain.UsageError(fmt.Sprintf("invalid search: %s", err))
}
unsigned.SetShareSearch(&q)
} else {
if len(args) != 1 {
return cmdmain.UsageError("share takes at most one argument")
}
target, ok := blob.Parse(args[0])
if !ok {
return cmdmain.UsageError("invalid blobref")
}
unsigned.SetShareTarget(target)
}
if c.duration != 0 {
unsigned.SetShareExpiration(time.Now().Add(c.duration))
}
pr, err := getUploader().UploadAndSignBlob(unsigned)
handleResult("share", pr, err)
return nil
}
示例10: MustGetBlobRef
// MustGetBlobRef returns a non-nil BlobRef from req, as given by param.
// If it doesn't, it panics with a value understood by Recover or RecoverJSON.
func MustGetBlobRef(req *http.Request, param string) blob.Ref {
br, ok := blob.Parse(MustGet(req, param))
if !ok {
panic(InvalidParameterError(param))
}
return br
}
示例11: EnumerateBlobs
func (s *storage) EnumerateBlobs(ctx *context.Context, dest chan<- blob.SizedRef, after string, limit int) error {
defer close(dest)
iter := s.index.Find(after, "")
n := 0
for iter.Next() {
if iter.Key() == after {
continue
}
br, ok := blob.Parse(iter.Key())
if !ok {
panic("Bogus encrypt index key: " + iter.Key())
}
plainSize, ok := parseMetaValuePlainSize(iter.Value())
if !ok {
panic("Bogus encrypt index value: " + iter.Value())
}
select {
case dest <- blob.SizedRef{br, plainSize}:
case <-ctx.Done():
return context.ErrCanceled
}
n++
if limit != 0 && n >= limit {
break
}
}
return iter.Close()
}
示例12: fileSchemaRefFromBlob
// Given a described blob, optionally follows a camliContent and
// returns the file's schema blobref and its fileinfo (if found).
func (pr *publishRequest) fileSchemaRefFromBlob(des *search.DescribedBlob) (fileref blob.Ref, fileinfo *search.FileInfo, ok bool) {
if des == nil {
http.NotFound(pr.rw, pr.req)
return
}
if des.Permanode != nil {
// TODO: get "forceMime" attr out of the permanode? or
// fileName content-disposition?
if cref := des.Permanode.Attr.Get("camliContent"); cref != "" {
cbr, ok2 := blob.Parse(cref)
if !ok2 {
http.Error(pr.rw, "bogus camliContent", 500)
return
}
des = des.PeerBlob(cbr)
if des == nil {
http.Error(pr.rw, "camliContent not a peer in describe", 500)
return
}
}
}
if des.CamliType == "file" {
return des.BlobRef, des.File, true
}
http.Error(pr.rw, "failed to find fileSchemaRefFromBlob", 404)
return
}
示例13: serveHTTP
func (h *shareHandler) serveHTTP(rw http.ResponseWriter, req *http.Request) error {
var err error
pathSuffix := httputil.PathSuffix(req)
if len(pathSuffix) == 0 {
// This happens during testing because we don't go through PrefixHandler
pathSuffix = strings.TrimLeft(req.URL.Path, "/")
}
pathParts := strings.SplitN(pathSuffix, "/", 2)
blobRef, ok := blob.Parse(pathParts[0])
if !ok {
err = &shareError{code: invalidURL, response: badRequest,
message: fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix)}
} else {
err = handleGetViaSharing(rw, req, blobRef, h.fetcher)
}
if se, ok := err.(*shareError); ok {
switch se.response {
case badRequest:
httputil.BadRequestError(rw, err.Error())
case unauthorizedRequest:
log.Print(err)
auth.SendUnauthorized(rw, req)
}
}
return err
}
示例14: newHandlerFromConfig
func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handler, error) {
indexPrefix := conf.RequiredString("index") // TODO: add optional help tips here?
ownerBlobStr := conf.RequiredString("owner")
devBlockStartupPrefix := conf.OptionalString("devBlockStartupOn", "")
if err := conf.Validate(); err != nil {
return nil, err
}
if devBlockStartupPrefix != "" {
_, err := ld.GetHandler(devBlockStartupPrefix)
if err != nil {
return nil, fmt.Errorf("search handler references bogus devBlockStartupOn handler %s: %v", devBlockStartupPrefix, err)
}
}
indexHandler, err := ld.GetHandler(indexPrefix)
if err != nil {
return nil, fmt.Errorf("search config references unknown handler %q", indexPrefix)
}
indexer, ok := indexHandler.(Index)
if !ok {
return nil, fmt.Errorf("search config references invalid indexer %q (actually a %T)", indexPrefix, indexHandler)
}
ownerBlobRef, ok := blob.Parse(ownerBlobStr)
if !ok {
return nil, fmt.Errorf("search 'owner' has malformed blobref %q; expecting e.g. sha1-xxxxxxxxxxxx",
ownerBlobStr)
}
return &Handler{
index: indexer,
owner: ownerBlobRef,
}, nil
}
示例15: serveFiles
func (sh *Handler) serveFiles(rw http.ResponseWriter, req *http.Request) {
var ret camtypes.FileSearchResponse
defer httputil.ReturnJSON(rw, &ret)
br, ok := blob.Parse(req.FormValue("wholedigest"))
if !ok {
ret.Error = "Missing or invalid 'wholedigest' param"
ret.ErrorType = "input"
return
}
files, err := sh.index.ExistingFileSchemas(br)
if err != nil {
ret.Error = err.Error()
ret.ErrorType = "server"
return
}
// the ui code expects an object
if files == nil {
files = []blob.Ref{}
}
ret.Files = files
return
}