Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package local | |
| 6 | |
| 7 import ( | |
| 8 "encoding/json" | |
| 9 "io" | |
| 10 "io/ioutil" | |
| 11 ) | |
| 12 | |
| 13 // Name of the directory inside an installation root reserved for cipd stuff. | |
| 14 const SiteServiceDir = ".cipd" | |
| 15 | |
| 16 // Name of the directory inside the package reserved for cipd stuff. | |
| 17 const packageServiceDir = ".cipdpkg" | |
| 18 | |
| 19 // Name of the manifest file inside the package. | |
| 20 const manifestName = packageServiceDir + "/manifest.json" | |
| 21 | |
| 22 // Format version to write to the manifest file. | |
| 23 const manifestFormatVersion = "1" | |
| 24 | |
| 25 // Manifest defines structure of manifest.json file. | |
| 26 type Manifest struct { | |
| 27 FormatVersion string `json:"format_version"` | |
| 28 PackageName string `json:"package_name"` | |
| 29 } | |
| 30 | |
| 31 // readManifest reads and decodes manifest JSON from io.Reader. | |
| 32 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.
| |
| 33 blob, err := ioutil.ReadAll(r) | |
| 34 if err != nil { | |
| 35 return Manifest{}, err | |
| 36 } | |
| 37 manifest := Manifest{} | |
| 38 err = json.Unmarshal(blob, &manifest) | |
| 39 if err != nil { | |
| 40 return Manifest{}, err | |
| 41 } | |
| 42 return manifest, nil | |
| 43 } | |
| 44 | |
| 45 // writeManifest encodes and writes manifest JSON to io.Writer. | |
| 46 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
| |
| 47 data, err := json.MarshalIndent(m, "", " ") | |
| 48 if err != nil { | |
| 49 return err | |
| 50 } | |
| 51 _, err = w.Write(data) | |
| 52 return err | |
| 53 } | |
| OLD | NEW |