本文整理汇总了Golang中kythe/io/kythe/go/platform/indexpack.Archive.WriteUnit方法的典型用法代码示例。如果您正苦于以下问题:Golang Archive.WriteUnit方法的具体用法?Golang Archive.WriteUnit怎么用?Golang Archive.WriteUnit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kythe/io/kythe/go/platform/indexpack.Archive
的用法示例。
在下文中一共展示了Archive.WriteUnit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: packIndex
func packIndex(ctx context.Context, pack *indexpack.Archive, idx *kindex.Compilation) error {
for _, data := range idx.Files {
if path, err := pack.WriteFile(ctx, data.Content); err != nil {
return fmt.Errorf("error writing file %v: %v", data.Info, err)
} else if !*quiet {
log.Println("Wrote file to", path)
}
}
path, err := pack.WriteUnit(ctx, formatKey, idx.Proto)
if err != nil {
return fmt.Errorf("error writing compilation unit: %v", err)
}
fmt.Println(strings.TrimSuffix(path, ".unit"))
return nil
}
示例2: Store
// Store writes the compilation units of p to the specified archive and returns
// its unit file names. This has the side-effect of updating the required
// inputs of the compilations so that they contain the proper digest values.
func (p *Package) Store(ctx context.Context, a *indexpack.Archive) ([]string, error) {
const formatKey = "kythe"
var unitFiles []string
for _, cu := range p.Units {
// Pack the required inputs into the archive.
for _, ri := range cu.RequiredInput {
// Check whether we already did this, so Store can be idempotent.
//
// When addFiles first adds the required input to the record, we
// know its path but have not yet fetched its contents -- that step
// is deferred until we are ready to store them for output (i.e.,
// now). Once we have fetched the file contents, we'll update the
// field with the correct digest value. We only want to do this
// once, per input, however.
path := ri.Info.Digest
if !strings.Contains(path, "/") {
continue
}
// Fetch the file and store it into the archive. We may get a
// cache hit here, handled by fetchAndStore.
digest, err := p.ext.fetchAndStore(ctx, path, a)
if err != nil {
return nil, err
}
ri.Info.Digest = digest
}
// Pack the compilation unit into the archive.
fn, err := a.WriteUnit(ctx, formatKey, cu)
if err != nil {
return nil, err
}
unitFiles = append(unitFiles, fn)
}
return unitFiles, nil
}