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


Golang ImageManifest.UnmarshalJSON方法代碼示例

本文整理匯總了Golang中github.com/appc/acbuild/Godeps/_workspace/src/github.com/appc/spec/schema.ImageManifest.UnmarshalJSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang ImageManifest.UnmarshalJSON方法的具體用法?Golang ImageManifest.UnmarshalJSON怎麽用?Golang ImageManifest.UnmarshalJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/appc/acbuild/Godeps/_workspace/src/github.com/appc/spec/schema.ImageManifest的用法示例。


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

示例1: checkMinimalContainer

func checkMinimalContainer(t *testing.T, acipath string, expectedManifest schema.ImageManifest) {
	// Check that there are no files in the rootfs
	files, err := ioutil.ReadDir(path.Join(acipath, aci.RootfsDir))
	if err != nil {
		t.Errorf("%v", err)
	}
	if len(files) != 0 {
		t.Errorf("rootfs in aci contains files, should be empty")
	}

	// Check that the manifest is no bigger than it needs to be
	manblob, err := ioutil.ReadFile(path.Join(acipath, aci.ManifestFile))
	if err != nil {
		t.Errorf("%v", err)
	}

	var man schema.ImageManifest

	err = man.UnmarshalJSON(manblob)
	if err != nil {
		t.Errorf("invalid manifest schema: %v", err)
	}

	if str := pretty.Compare(man, expectedManifest); str != "" {
		t.Errorf("unexpected manifest:\n%s", str)
	}
}
開發者ID:aaronlevy,項目名稱:acbuild,代碼行數:27,代碼來源:begin_test.go

示例2: ManifestFromImage

// ManifestFromImage extracts a new schema.ImageManifest from the given ACI image.
func ManifestFromImage(rs io.ReadSeeker) (*schema.ImageManifest, error) {
	var im schema.ImageManifest

	tr, err := NewCompressedTarReader(rs)
	if err != nil {
		return nil, err
	}
	defer tr.Close()

	for {
		hdr, err := tr.Next()
		switch err {
		case io.EOF:
			return nil, errors.New("missing manifest")
		case nil:
			if filepath.Clean(hdr.Name) == ManifestFile {
				data, err := ioutil.ReadAll(tr)
				if err != nil {
					return nil, err
				}
				if err := im.UnmarshalJSON(data); err != nil {
					return nil, err
				}
				return &im, nil
			}
		default:
			return nil, fmt.Errorf("error extracting tarball: %v", err)
		}
	}
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:31,代碼來源:file.go

示例3: validate

func validate(imOK bool, im io.Reader, rfsOK bool, files []string) error {
	defer func() {
		if rc, ok := im.(io.Closer); ok {
			rc.Close()
		}
	}()
	if !imOK {
		return ErrNoManifest
	}
	if !rfsOK {
		return ErrNoRootFS
	}
	b, err := ioutil.ReadAll(im)
	if err != nil {
		return fmt.Errorf("error reading image manifest: %v", err)
	}
	var a schema.ImageManifest
	if err := a.UnmarshalJSON(b); err != nil {
		return fmt.Errorf("image manifest validation failed: %v", err)
	}
	if a.ACVersion.LessThanMajor(schema.AppContainerVersion) {
		return ErrOldVersion{
			version: a.ACVersion,
		}
	}
	for _, f := range files {
		if !strings.HasPrefix(f, "rootfs") {
			return fmt.Errorf("unrecognized file path in layout: %q", f)
		}
	}
	return nil
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:32,代碼來源:layout.go

示例4: createImageManifest

func createImageManifest(imj string) (*schema.ImageManifest, error) {
	var im schema.ImageManifest
	err := im.UnmarshalJSON([]byte(imj))
	if err != nil {
		return nil, err
	}
	return &im, nil
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:8,代碼來源:acirenderer_test.go

示例5: prettyPrintMan

func prettyPrintMan(manblob []byte) []byte {
	var man schema.ImageManifest

	err := man.UnmarshalJSON(manblob)
	if err != nil {
		panic(err)
	}

	manblob2, err := json.MarshalIndent(man, "", "    ")
	if err != nil {
		panic(err)
	}
	return manblob2
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:14,代碼來源:cat-manifest_test.go

示例6: CatManifest

// CatManifest will print to stdout the manifest from the ACI stored at
// aciPath, optionally inserting whitespace to make it more human readable.
func CatManifest(aciPath string, prettyPrint bool) (err error) {
	finfo, err := os.Stat(aciPath)
	switch {
	case os.IsNotExist(err):
		return fmt.Errorf("no such file or directory: %s", aciPath)
	case err != nil:
		return err
	case finfo.IsDir():
		return fmt.Errorf("%s is a directory, not an ACI", aciPath)
	default:
		break
	}

	file, err := os.Open(aciPath)
	if err != nil {
		return err
	}
	defer file.Close()

	tr, err := aci.NewCompressedTarReader(file)
	if err != nil {
		return fmt.Errorf("error decompressing image: %v", err)
	}
	defer tr.Close()

	for {
		hdr, err := tr.Next()
		switch {
		case err == io.EOF:
			return fmt.Errorf("manifest not found in ACI %s", aciPath)
		case err != nil:
			return err
		case hdr.Name == "manifest":
			manblob, err := ioutil.ReadAll(tr)
			if err != nil {
				return err
			}
			var man schema.ImageManifest
			err = man.UnmarshalJSON(manblob)
			if err != nil {
				return err
			}
			return util.PrintManifest(&man, prettyPrint)
		}
	}
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:48,代碼來源:cat-manifest.go

示例7: checkManifest

func checkManifest(t *testing.T, workingDir string, wantedManifest schema.ImageManifest) {
	acipath := path.Join(workingDir, ".acbuild", "currentaci")

	manblob, err := ioutil.ReadFile(path.Join(acipath, aci.ManifestFile))
	if err != nil {
		panic(err)
	}

	var man schema.ImageManifest

	err = man.UnmarshalJSON(manblob)
	if err != nil {
		t.Errorf("invalid manifest schema: %v", err)
	}

	if str := pretty.Compare(man, wantedManifest); str != "" {
		t.Errorf("unexpected manifest:\n%s", str)
	}
}
開發者ID:rhencke,項目名稱:acbuild,代碼行數:19,代碼來源:common.go

示例8: 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)
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:45,代碼來源:replace-manifest.go

示例9: testCat

func testCat(t *testing.T, workingDir string) {
	wantedManblob, err := ioutil.ReadFile(path.Join(workingDir, ".acbuild", "currentaci", aci.ManifestFile))
	if err != nil {
		panic(err)
	}
	wantedManblob = append(wantedManblob, byte('\n'))

	var man schema.ImageManifest
	err = man.UnmarshalJSON(wantedManblob)
	if err != nil {
		panic(err)
	}

	_, manblob, _, err := runACBuild(workingDir, "cat-manifest")
	if err != nil {
		t.Fatalf("%v", err)
	}

	if manblob != string(wantedManblob) {
		t.Fatalf("printed manifest and manifest on disk differ")
	}

	wantedManblob = prettyPrintMan(wantedManblob)
	wantedManblob = append(wantedManblob, byte('\n'))

	_, manblob, _, err = runACBuild(workingDir, "cat-manifest", "--pretty-print")
	if err != nil {
		t.Fatalf("%v", err)
	}

	if manblob != string(wantedManblob) {
		t.Fatalf("pretty printed manifest and manifest on disk differ")
	}

	checkManifest(t, workingDir, man)
	checkEmptyRootfs(t, workingDir)
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:37,代碼來源:cat-manifest_test.go


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