Chromium Code Reviews| Index: go/src/infra/tools/cipd/local/manifest.go |
| diff --git a/go/src/infra/tools/cipd/local/manifest.go b/go/src/infra/tools/cipd/local/manifest.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f7b0045fc59b7dae56b51849d41ca95fc856a96 |
| --- /dev/null |
| +++ b/go/src/infra/tools/cipd/local/manifest.go |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package local |
| + |
| +import ( |
| + "encoding/json" |
| + "io" |
| + "io/ioutil" |
| +) |
| + |
| +// Name of the directory inside an installation root reserved for cipd stuff. |
| +const SiteServiceDir = ".cipd" |
| + |
| +// Name of the directory inside the package reserved for cipd stuff. |
| +const packageServiceDir = ".cipdpkg" |
| + |
| +// Name of the manifest file inside the package. |
| +const manifestName = packageServiceDir + "/manifest.json" |
| + |
| +// Format version to write to the manifest file. |
| +const manifestFormatVersion = "1" |
| + |
| +// Manifest defines structure of manifest.json file. |
| +type Manifest struct { |
| + FormatVersion string `json:"format_version"` |
| + PackageName string `json:"package_name"` |
| +} |
| + |
| +// readManifest reads and decodes manifest JSON from io.Reader. |
| +func readManifest(r io.Reader) (Manifest, error) { |
|
nodir
2015/05/13 01:25:29
nit: if you give names to return values, there wil
Vadim Sh.
2015/05/13 03:08:06
Done.
|
| + blob, err := ioutil.ReadAll(r) |
| + if err != nil { |
| + return Manifest{}, err |
| + } |
| + manifest := Manifest{} |
| + err = json.Unmarshal(blob, &manifest) |
| + if err != nil { |
| + return Manifest{}, err |
| + } |
| + return manifest, nil |
| +} |
| + |
| +// writeManifest encodes and writes manifest JSON to io.Writer. |
| +func writeManifest(m *Manifest, w io.Writer) error { |
|
nodir
2015/05/13 01:25:29
How do you judge whether a func should be a method
Vadim Sh.
2015/05/13 03:08:06
I flip a coin...
Basically, for immutable types I
|
| + data, err := json.MarshalIndent(m, "", " ") |
| + if err != nil { |
| + return err |
| + } |
| + _, err = w.Write(data) |
| + return err |
| +} |