本文整理汇总了Golang中github.com/appc/spec/schema.ImageManifest.MarshalJSON方法的典型用法代码示例。如果您正苦于以下问题:Golang ImageManifest.MarshalJSON方法的具体用法?Golang ImageManifest.MarshalJSON怎么用?Golang ImageManifest.MarshalJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/appc/spec/schema.ImageManifest
的用法示例。
在下文中一共展示了ImageManifest.MarshalJSON方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PrintManifest
// PrintManifest will print the given manifest to stdout, optionally inserting
// whitespace to make it more human readable.
func PrintManifest(man *schema.ImageManifest, prettyPrint bool) error {
var manblob []byte
var err error
if prettyPrint {
manblob, err = json.MarshalIndent(man, "", " ")
} else {
manblob, err = man.MarshalJSON()
}
if err != nil {
return err
}
fmt.Println(string(manblob))
return nil
}
示例2: PrepareACIDir
// PrepareACIDir takes a manifest and a path to rootfs and lay them out in a
// temp directory that conforms to the layout of ACI image.
func PrepareACIDir(manifest *schema.ImageManifest, rootfs string) (string, error) {
// Create a temp directory to hold the manifest and rootfs
tmpDir, err := ioutil.TempDir("", "")
if err != nil {
return "", fmt.Errorf("error creating temp directory: %v", err)
}
// Write the manifest file
tmpManifest, err := os.Create(filepath.Join(tmpDir, aci.ManifestFile))
if err != nil {
return "", fmt.Errorf("error creating temporary manifest: %v", err)
}
defer tmpManifest.Close()
manifestBytes, err := manifest.MarshalJSON()
if err != nil {
return "", fmt.Errorf("error marshalling manifest: %v", err)
}
_, err = tmpManifest.Write(manifestBytes)
if err != nil {
return "", fmt.Errorf("error writing manifest to temp file: %v", err)
}
if err := tmpManifest.Sync(); err != nil {
return "", fmt.Errorf("error syncing manifest file: %v", err)
}
if rootfs == "" {
// Create an (empty) rootfs
if err := os.Mkdir(filepath.Join(tmpDir, aci.RootfsDir), 0755); err != nil {
return "", fmt.Errorf("error making an empty rootfs directory: %v", err)
}
} else {
if err := shutil.CopyTree(rootfs, filepath.Join(tmpDir, aci.RootfsDir), &shutil.CopyTreeOptions{
Symlinks: true,
IgnoreDanglingSymlinks: true,
CopyFunction: shutil.Copy,
}); err != nil {
return "", fmt.Errorf("Unable to copy rootfs to a temporary directory: %s", err)
}
}
return tmpDir, nil
}
示例3: createACI
func createACI(dir string, fs map[string]*deb, image string, m *schema.ImageManifest) error {
idir, err := ioutil.TempDir(dir, "image")
if err != nil {
return errorf(err.Error())
}
rootfs := filepath.Join(idir, "rootfs")
os.MkdirAll(rootfs, 0755)
for _, d := range fs {
err := run(exec.Command("cp", "-a", d.Path+"/.", rootfs))
if err != nil {
return err
}
i, err := types.SanitizeACIdentifier(
fmt.Sprintf("debian.org/deb/%v", d.Name))
if err != nil {
return errorf(err.Error())
}
a, err := types.NewACIdentifier(i)
if err != nil {
return errorf(err.Error())
}
m.Annotations.Set(
*a, fmt.Sprintf("%v/%v", d.Arch, d.Version))
}
bytes, err := m.MarshalJSON()
if err != nil {
return errorf(err.Error())
}
if err := ioutil.WriteFile(filepath.Join(idir, "manifest"), bytes, 0644); err != nil {
return errorf(err.Error())
}
if err := run(exec.Command("actool", "build", "-overwrite", idir, image)); err != nil {
return err
}
return nil
}