本文整理匯總了Golang中github.com/appc/acbuild/Godeps/_workspace/src/github.com/appc/spec/schema.ImageManifest.MarshalJSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang ImageManifest.MarshalJSON方法的具體用法?Golang ImageManifest.MarshalJSON怎麽用?Golang ImageManifest.MarshalJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/appc/acbuild/Godeps/_workspace/src/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: ReplaceManifest
// ReplaceManifest will replace the manifest in the expanded ACI stored at
// a.CurrentACIPath with the new manifest stored at manifestPath
func (a *ACBuild) ReplaceManifest(manifestPath string) (err error) {
if err = a.lock(); err != nil {
return err
}
defer func() {
if err1 := a.unlock(); err == nil {
err = err1
}
}()
finfo, err := os.Stat(manifestPath)
switch {
case os.IsNotExist(err):
return fmt.Errorf("no such file or directory: %s", manifestPath)
case err != nil:
return err
case finfo.IsDir():
return fmt.Errorf("%s is a directory", manifestPath)
default:
break
}
manblob, err := ioutil.ReadFile(manifestPath)
if err != nil {
return err
}
// Marshal and Unmarshal the manifest to assert that it's valid and to
// strip any whitespace
var man schema.ImageManifest
err = man.UnmarshalJSON(manblob)
if err != nil {
return err
}
manblob, err = man.MarshalJSON()
if err != nil {
return err
}
return ioutil.WriteFile(path.Join(a.CurrentACIPath, aci.ManifestFile), manblob, 0755)
}
示例3: TestBeginLocalACI
func TestBeginLocalACI(t *testing.T) {
wim := schema.ImageManifest{
ACKind: schema.ImageManifestKind,
ACVersion: schema.AppContainerVersion,
Name: *types.MustACIdentifier("acbuild-begin-test"),
Labels: types.Labels{
types.Label{
Name: *types.MustACIdentifier("version"),
Value: "9001",
},
},
App: &types.App{
Exec: types.Exec{"/bin/nethack4", "-D", "wizard"},
User: "0",
Group: "0",
Environment: types.Environment{
types.EnvironmentVariable{
Name: "FOO",
Value: "BAR",
},
},
MountPoints: []types.MountPoint{
types.MountPoint{
Name: *types.MustACName("nethack4-data"),
Path: "/root/nethack4-data",
ReadOnly: true,
},
},
Ports: []types.Port{
types.Port{
Name: *types.MustACName("gopher"),
Protocol: "tcp",
Port: 70,
Count: 1,
},
},
},
Annotations: types.Annotations{
types.Annotation{
Name: *types.MustACIdentifier("author"),
Value: "the acbuild devs",
},
},
Dependencies: types.Dependencies{
types.Dependency{
ImageName: *types.MustACIdentifier("quay.io/gnu/hurd"),
},
},
}
manblob, err := wim.MarshalJSON()
if err != nil {
panic(err)
}
tmpexpandedaci := mustTempDir()
defer os.RemoveAll(tmpexpandedaci)
err = ioutil.WriteFile(path.Join(tmpexpandedaci, aci.ManifestFile), manblob, 0644)
if err != nil {
panic(err)
}
err = os.Mkdir(path.Join(tmpexpandedaci, aci.RootfsDir), 0755)
if err != nil {
panic(err)
}
tmpaci, err := ioutil.TempFile("", "acbuild-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpaci.Name())
aw := aci.NewImageWriter(wim, tar.NewWriter(tmpaci))
err = filepath.Walk(tmpexpandedaci, aci.BuildWalker(tmpexpandedaci, aw, nil))
aw.Close()
if err != nil {
panic(err)
}
tmpaci.Close()
tmpdir := mustTempDir()
defer cleanUpTest(tmpdir)
err = runAcbuild(tmpdir, "begin", tmpaci.Name())
if err != nil {
t.Fatalf("%v", err)
}
checkMinimalContainer(t, path.Join(tmpdir, ".acbuild", "currentaci"), wim)
}