當前位置: 首頁>>代碼示例>>Golang>>正文


Golang schema.StaticSet類代碼示例

本文整理匯總了Golang中camlistore/org/pkg/schema.StaticSet的典型用法代碼示例。如果您正苦於以下問題:Golang StaticSet類的具體用法?Golang StaticSet怎麽用?Golang StaticSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StaticSet類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: UploadDir

// If modTime is zero, it's not used.
func (id *IndexDeps) UploadDir(dirName string, children []blob.Ref, modTime time.Time) blob.Ref {
	// static-set entries blob
	ss := new(schema.StaticSet)
	for _, child := range children {
		ss.Add(child)
	}
	ssjson := ss.Blob().JSON()
	ssb := &test.Blob{Contents: ssjson}
	id.BlobSource.AddBlob(ssb)
	_, err := id.Index.ReceiveBlob(ssb.BlobRef(), ssb.Reader())
	if err != nil {
		id.Fatalf("UploadDir.ReceiveBlob: %v", err)
	}

	// directory blob
	bb := schema.NewDirMap(dirName)
	bb.PopulateDirectoryMap(ssb.BlobRef())
	if !modTime.IsZero() {
		bb.SetModTime(modTime)
	}
	dirjson, err := bb.JSON()
	if err != nil {
		id.Fatalf("UploadDir.JSON: %v", err)
	}
	dirb := &test.Blob{Contents: dirjson}
	id.BlobSource.AddBlob(dirb)
	_, err = id.Index.ReceiveBlob(dirb.BlobRef(), dirb.Reader())
	if err != nil {
		id.Fatalf("UploadDir.ReceiveBlob: %v", err)
	}
	return dirb.BlobRef()
}
開發者ID:stevearm,項目名稱:camlistore,代碼行數:33,代碼來源:tests.go

示例2: directoryStaticSet

func (n *node) directoryStaticSet() (*schema.StaticSet, error) {
	ss := new(schema.StaticSet)
	for _, c := range n.children {
		pr, err := c.PutResult()
		if err != nil {
			return nil, fmt.Errorf("Error populating directory static set for child %q: %v", c.fullPath, err)
		}
		ss.Add(pr.BlobRef)
	}
	return ss, nil
}
開發者ID:camlistore,項目名稱:camlistore,代碼行數:11,代碼來源:files.go

示例3: uploadNode

func (up *Uploader) uploadNode(n *node) (*client.PutResult, error) {
	fi := n.fi
	mode := fi.Mode()
	if mode&os.ModeType == 0 {
		return up.uploadNodeRegularFile(n)
	}
	bb := schema.NewCommonFileMap(n.fullPath, fi)
	switch {
	case mode&os.ModeSymlink != 0:
		// TODO(bradfitz): use VFS here; not os.Readlink
		target, err := os.Readlink(n.fullPath)
		if err != nil {
			return nil, err
		}
		bb.SetSymlinkTarget(target)
	case mode&os.ModeDevice != 0:
		// including mode & os.ModeCharDevice
		fallthrough
	case mode&os.ModeSocket != 0:
		fallthrough
	case mode&os.ModeNamedPipe != 0: // FIFO
		fallthrough
	default:
		return nil, fmt.Errorf("camput.files: unsupported file type %v for file %v", mode, n.fullPath)
	case fi.IsDir():
		ss := new(schema.StaticSet)
		for _, c := range n.children {
			pr, err := c.PutResult()
			if err != nil {
				return nil, fmt.Errorf("Error populating directory static set for child %q: %v", c.fullPath, err)
			}
			ss.Add(pr.BlobRef)
		}
		sspr, err := up.UploadBlob(ss)
		if err != nil {
			return nil, err
		}
		bb.PopulateDirectoryMap(sspr.BlobRef)
	}

	mappr, err := up.UploadBlob(bb)
	if err == nil {
		if !mappr.Skipped {
			vlog.Printf("Uploaded %q, %s for %s", bb.Type(), mappr.BlobRef, n.fullPath)
		}
	} else {
		vlog.Printf("Error uploading map for %s (%s, %s): %v", n.fullPath, bb.Type(), bb.Blob().BlobRef(), err)
	}
	return mappr, err

}
開發者ID:ngerakines,項目名稱:camlistore,代碼行數:51,代碼來源:files.go

示例4: uploadNode

func (up *Uploader) uploadNode(n *node) (*client.PutResult, error) {
	fi := n.fi
	m := schema.NewCommonFileMap(n.fullPath, fi)
	mode := fi.Mode()
	switch {
	case mode&os.ModeSymlink != 0:
		// TODO(bradfitz): use VFS here; PopulateSymlinkMap uses os.Readlink directly.
		if err := schema.PopulateSymlinkMap(m, n.fullPath); err != nil {
			return nil, err
		}
	case mode&os.ModeDevice != 0:
		// including mode & os.ModeCharDevice
		fallthrough
	case mode&os.ModeSocket != 0:
		fallthrough
	case mode&os.ModeNamedPipe != 0: // FIFO
		fallthrough
	default:
		return nil, schema.ErrUnimplemented
	case mode&os.ModeType == 0: // regular file
		m["camliType"] = "file"

		file, err := up.open(n.fullPath)
		if err != nil {
			return nil, err
		}
		defer file.Close()

		statReceiver := up.altStatReceiver
		if statReceiver == nil {
			// TODO(bradfitz): just make Client be a
			// StatReceiver? move remote's ReceiveBlob ->
			// Upload wrapper into Client itself?
			statReceiver = remote.NewFromClient(up.Client)
		}

		schemaWriteFileMap := schema.WriteFileMap
		if up.rollSplits {
			schemaWriteFileMap = schema.WriteFileMapRolling
		}
		blobref, err := schemaWriteFileMap(statReceiver, m, io.LimitReader(file, fi.Size()))
		if err != nil {
			return nil, err
		}
		// TODO(bradfitz): taking a PutResult here is kinda
		// gross.  should instead make a blobserver.Storage
		// wrapper type that can track some of this?  or that
		// updates the client stats directly or something.
		{
			json, _ := schema.MapToCamliJSON(m)
			pr := &client.PutResult{BlobRef: blobref, Size: int64(len(json)), Skipped: false}
			return pr, nil
		}
	case fi.IsDir():
		ss := new(schema.StaticSet)
		for _, c := range n.children {
			pr, err := c.PutResult()
			if err != nil {
				return nil, fmt.Errorf("Error populating directory static set for child %q: %v", c.fullPath, err)
			}
			ss.Add(pr.BlobRef)
		}
		sspr, err := up.UploadMap(ss.Map())
		if err != nil {
			return nil, err
		}
		schema.PopulateDirectoryMap(m, sspr.BlobRef)
	}

	mappr, err := up.UploadMap(m)
	if err == nil {
		if !mappr.Skipped {
			vlog.Printf("Uploaded %q, %s for %s", m["camliType"], mappr.BlobRef, n.fullPath)
		}
	} else {
		vlog.Printf("Error uploading map %v: %v", m, err)
	}
	return mappr, err

}
開發者ID:splade,項目名稱:camlistore,代碼行數:80,代碼來源:files.go

示例5: RunCommand

func (c *makeStaticCmd) RunCommand(args []string) error {
	if len(args) != 1 {
		return cmdmain.UsageError("requires a permanode")
	}
	pn, ok := blob.Parse(args[0])
	if !ok {
		return cmdmain.UsageError("invalid permanode argument")
	}

	cl := newClient(c.server)
	res, err := cl.Describe(&search.DescribeRequest{
		BlobRefs: []blob.Ref{pn},
		Rules: []*search.DescribeRule{
			{
				IfResultRoot: true,
				Attrs:        []string{"camliMember"},
				Rules: []*search.DescribeRule{
					{Attrs: []string{"camliContent"}},
				},
			},
		},
	})
	if err != nil {
		return err
	}

	camliType := func(ref string) string {
		m := res.Meta[ref]
		if m == nil {
			return ""
		}
		return m.CamliType
	}

	var ss schema.StaticSet
	pnDes, ok := res.Meta[pn.String()]
	if !ok {
		return fmt.Errorf("permanode %v not described", pn)
	}
	if pnDes.Permanode == nil {
		return fmt.Errorf("blob %v is not a permanode", pn)
	}
	members := pnDes.Permanode.Attr["camliMember"]
	if len(members) == 0 {
		return fmt.Errorf("permanode %v has no camliMember attributes", pn)
	}
	for _, fileRefStr := range members {
		if camliType(fileRefStr) != "permanode" {
			continue
		}
		contentRef := res.Meta[fileRefStr].Permanode.Attr.Get("camliContent")
		if contentRef == "" {
			continue
		}
		if camliType(contentRef) == "file" {
			ss.Add(blob.MustParse(contentRef))
		}
	}

	b := ss.Blob()
	_, err = cl.UploadBlob(b)
	if err != nil {
		return err
	}
	title := pnDes.Title()
	title = strings.Replace(title, string(os.PathSeparator), "", -1)
	if title == "" {
		title = pn.String()
	}
	dir := schema.NewDirMap(title).PopulateDirectoryMap(b.BlobRef())
	dirBlob := dir.Blob()
	_, err = cl.UploadBlob(dirBlob)
	if err == nil {
		fmt.Println(dirBlob.BlobRef().String())
	}
	return err
}
開發者ID:camarox53,項目名稱:coreos-baremetal,代碼行數:77,代碼來源:makestatic.go


注:本文中的camlistore/org/pkg/schema.StaticSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。