本文整理匯總了Golang中camlistore/org/pkg/blobref.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestHubFiring
func TestHubFiring(t *testing.T) {
hub := &SimpleBlobHub{}
ch := make(chan *blobref.BlobRef)
bch := make(chan *blobref.BlobRef)
blob := blobref.Parse("sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
blobsame := blobref.Parse("sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33")
hub.NotifyBlobReceived(blob) // no-op
hub.RegisterListener(ch)
hub.RegisterBlobListener(blob, bch)
hub.NotifyBlobReceived(blobsame)
tmr1 := time.NewTimer(1e9)
select {
case <-tmr1.C:
t.Fatal("timer expired on receiving from ch")
case got := <-ch:
if !blob.Equal(got) {
t.Fatalf("got wrong blob")
}
}
select {
case <-tmr1.C:
t.Fatal("timer expired on receiving from bch")
case got := <-bch:
if !blob.Equal(got) {
t.Fatalf("got wrong blob")
}
}
tmr1.Stop()
}
示例2: StaticSet
// StaticSet returns the whole of the static set members of that directory
func (dr *DirReader) StaticSet() ([]*blobref.BlobRef, error) {
if dr.staticSet != nil {
return dr.staticSet, nil
}
staticSetBlobref := blobref.Parse(dr.ss.Entries)
if staticSetBlobref == nil {
return nil, fmt.Errorf("schema/filereader: Invalid blobref\n")
}
rsc, _, err := dr.fetcher.Fetch(staticSetBlobref)
if err != nil {
return nil, fmt.Errorf("schema/filereader: fetching schema blob %s: %v", staticSetBlobref, err)
}
ss, err := ParseSuperset(rsc)
if err != nil {
return nil, fmt.Errorf("schema/filereader: decoding schema blob %s: %v", staticSetBlobref, err)
}
if ss.Type != "static-set" {
return nil, fmt.Errorf("schema/filereader: expected \"static-set\" schema blob for %s, got %q", staticSetBlobref, ss.Type)
}
for _, s := range ss.Members {
member := blobref.Parse(s)
if member == nil {
return nil, fmt.Errorf("schema/filereader: invalid (static-set member) blobref\n")
}
dr.staticSet = append(dr.staticSet, member)
}
return dr.staticSet, nil
}
示例3: PathsOfSignerTarget
func (x *Index) PathsOfSignerTarget(signer, target *blobref.BlobRef) (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 := blobref.Parse(keyPart[2])
baseRef := blobref.Parse(valPart[1])
if claimRef == nil || baseRef == nil {
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
}
示例4: fromHTTP
// fromHTTP panics with an httputil value on failure
func (r *WithAttrRequest) fromHTTP(req *http.Request) {
r.Signer = blobref.Parse(req.FormValue("signer"))
r.Value = req.FormValue("value")
fuzzy := req.FormValue("fuzzy") // exact match if empty
fuzzyMatch := false
if fuzzy != "" {
lowered := strings.ToLower(fuzzy)
if lowered == "true" || lowered == "t" {
fuzzyMatch = true
}
}
r.Attr = req.FormValue("attr") // all attributes if empty
if r.Attr == "" { // and force fuzzy in that case.
fuzzyMatch = true
}
r.Fuzzy = fuzzyMatch
r.ThumbnailSize = thumbnailSize(req)
max := req.FormValue("max")
if max != "" {
maxR, err := strconv.Atoi(max)
if err != nil {
panic(httputil.InvalidParameterError("max"))
}
r.N = maxR
}
r.N = r.n()
}
示例5: 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) *blobref.BlobRef {
br := blobref.Parse(MustGet(req, param))
if br == nil {
panic(InvalidParameterError(param))
}
return br
}
示例6: 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 := blobref.Parse(ownerBlobStr)
if ownerBlobRef == nil {
return nil, fmt.Errorf("search 'owner' has malformed blobref %q; expecting e.g. sha1-xxxxxxxxxxxx",
ownerBlobStr)
}
return &Handler{
index: indexer,
owner: ownerBlobRef,
}, nil
}
示例7: 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 *blobref.BlobRef, 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 := blobref.Parse(cref)
if cbr == nil {
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
}
示例8: GetOwnerClaims
func (x *Index) GetOwnerClaims(permaNode, owner *blobref.BlobRef) (cl search.ClaimList, err error) {
keyId, err := x.keyId(owner)
if err == ErrNotFound {
err = nil
return
}
if err != nil {
return nil, err
}
prefix := pipes("claim", permaNode, keyId, "")
it := x.queryPrefixString(prefix)
defer closeIterator(it, &err)
for it.Next() {
keyPart := strings.Split(it.Key(), "|")
valPart := strings.Split(it.Value(), "|")
if len(keyPart) < 5 || len(valPart) < 3 {
continue
}
claimRef := blobref.Parse(keyPart[4])
if claimRef == nil {
continue
}
date, _ := time.Parse(time.RFC3339, keyPart[3])
cl = append(cl, &search.Claim{
BlobRef: claimRef,
Signer: owner,
Permanode: permaNode,
Date: date,
Type: urld(valPart[0]),
Attr: urld(valPart[1]),
Value: urld(valPart[2]),
})
}
return
}
示例9: serveDownload
func (ui *UIHandler) serveDownload(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
m := downloadPattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
fbr := blobref.Parse(m[1])
if fbr == nil {
http.Error(rw, "Invalid blobref", 400)
return
}
dh := &DownloadHandler{
Fetcher: ui.root.Storage,
Cache: ui.Cache,
}
dh.ServeHTTP(rw, req, fbr)
}
示例10: isDeleted
// isDeleted returns whether br (a blobref or a claim) should be considered deleted.
func (x *Index) isDeleted(br *blobref.BlobRef) bool {
var err error
it := x.queryPrefix(keyDeleted, br)
defer closeIterator(it, &err)
for it.Next() {
// parts are ["deleted", br.String(), blobref-of-delete-claim].
// see keyDeleted in keys.go
parts := strings.SplitN(it.Key(), "|", 3)
if len(parts) != 3 {
continue
}
delClaimRef := blobref.Parse(parts[2])
if delClaimRef == nil {
panic(fmt.Errorf("invalid deleted claim for %v", parts[1]))
}
// The recursive call on the blobref of the delete claim
// checks that the claim itself was not deleted, in which case
// br is not considered deleted anymore.
// TODO(mpl): Each delete and undo delete adds a level of
// recursion so this could recurse far. is there a way to
// go faster in a worst case scenario?
return !x.isDeleted(delClaimRef)
}
return false
}
示例11: ParsePayloadMap
func (vr *VerifyRequest) ParsePayloadMap() bool {
vr.PayloadMap = make(map[string]interface{})
pm := vr.PayloadMap
if err := json.Unmarshal(vr.bpj, &pm); err != nil {
return vr.fail("parse error; payload JSON is invalid")
}
if _, hasVersion := pm["camliVersion"]; !hasVersion {
return vr.fail("missing 'camliVersion' in the JSON payload")
}
signer, hasSigner := pm["camliSigner"]
if !hasSigner {
return vr.fail("missing 'camliSigner' in the JSON payload")
}
if _, ok := signer.(string); !ok {
return vr.fail("invalid 'camliSigner' in the JSON payload")
}
vr.CamliSigner = blobref.Parse(signer.(string))
if vr.CamliSigner == nil {
return vr.fail("malformed 'camliSigner' blobref in the JSON payload")
}
return true
}
示例12: RunCommand
func (c *attrCmd) RunCommand(args []string) error {
if len(args) != 3 {
return errors.New("Attr takes 3 args: <permanode> <attr> <value>")
}
permanode, attr, value := args[0], args[1], args[2]
var err error
pn := blobref.Parse(permanode)
if pn == nil {
return fmt.Errorf("Error parsing blobref %q", permanode)
}
bb := schema.NewSetAttributeClaim(pn, attr, value)
if c.add {
if c.del {
return errors.New("Add and del options are exclusive")
}
bb = schema.NewAddAttributeClaim(pn, attr, value)
} else {
// TODO: del, which can make <value> be optional
if c.del {
return errors.New("del not yet implemented")
}
}
put, err := getUploader().UploadAndSignBlob(bb)
handleResult(bb.Type(), put, err)
return nil
}
示例13: main
// TODO(rh): tame copy/paste code from cammount
func main() {
client.AddFlags()
flag.Parse()
cacheDir, err := ioutil.TempDir("", "camlicache")
if err != nil {
log.Fatalf("Error creating temp cache directory: %v", err)
}
defer os.RemoveAll(cacheDir)
diskcache, err := localdisk.New(cacheDir)
if err != nil {
log.Fatalf("Error setting up local disk cache: %v", err)
}
if flag.NArg() != 1 {
log.Fatal("usage: camwebdav <blobref>")
}
br := blobref.Parse(flag.Arg(0))
if br == nil {
log.Fatalf("%s was not a valid blobref.", flag.Arg(0))
}
client := client.NewOrFail()
fetcher := cacher.NewCachingFetcher(diskcache, client)
f = fs.NewCamliFileSystem(fetcher, br)
http.HandleFunc("/", webdav)
err = http.ListenAndServe(*davaddr, nil)
if err != nil {
log.Fatalf("Error starting WebDAV server: %v", err)
}
}
示例14: serveFileTree
func (ui *UIHandler) serveFileTree(rw http.ResponseWriter, req *http.Request) {
if ui.root.Storage == nil {
http.Error(rw, "No BlobRoot configured", 500)
return
}
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
m := treePattern.FindStringSubmatch(suffix)
if m == nil {
httputil.ErrorRouting(rw, req)
return
}
blobref := blobref.Parse(m[1])
if blobref == nil {
http.Error(rw, "Invalid blobref", 400)
return
}
fth := &FileTreeHandler{
Fetcher: ui.root.Storage,
file: blobref,
}
fth.ServeHTTP(rw, req)
}
示例15: main
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
client.AddFlags()
flag.Parse()
errorf := func(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg, args...)
os.Exit(2)
}
if n := flag.NArg(); n < 1 || n > 2 {
errorf("usage: cammount <mountpoint> [<root-blobref>]\n")
}
mountPoint := flag.Arg(0)
client := client.NewOrFail() // automatic from flags
cacheDir, err := ioutil.TempDir("", "camlicache")
if err != nil {
errorf("Error creating temp cache directory: %v\n", err)
}
defer os.RemoveAll(cacheDir)
diskcache, err := localdisk.New(cacheDir)
if err != nil {
errorf("Error setting up local disk cache: %v", err)
}
fetcher := cacher.NewCachingFetcher(diskcache, client)
var camfs *fs.CamliFileSystem
if flag.NArg() == 2 {
root := blobref.Parse(flag.Arg(1))
if root == nil {
errorf("Error parsing root blobref: %q\n", root)
}
var err error
camfs, err = fs.NewRootedCamliFileSystem(fetcher, root)
if err != nil {
errorf("Error creating root with %v: %v", root, err)
}
} else {
camfs = fs.NewCamliFileSystem(fetcher)
log.Printf("starting with fs %#v", camfs)
}
if *debug {
// TODO: set fs's logger
}
conn, err := fuse.Mount(mountPoint)
if err != nil {
log.Fatalf("Mount: %v", err)
}
err = conn.Serve(camfs)
if err != nil {
log.Fatalf("Serve: %v", err)
}
log.Printf("fuse process ending.")
}