Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: client/internal/common/json.go

Issue 2938823003: Move WriteJSONFile to its sole caller's package, with some refactoring. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/cmd/isolate/batch_archive.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package common
6
7 import (
8 "encoding/json"
9 "fmt"
10 "os"
11 )
12
13 // WriteJSONFile writes object as json encoded into filePath with 2 spaces
14 // indentation. File permission is set to user only.
15 func WriteJSONFile(filePath string, object interface{}) error {
16 d, err := json.MarshalIndent(object, "", " ")
17 if err != nil {
18 return fmt.Errorf("failed to encode %s: %s", filePath, err)
19 }
20
21 f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
22 if err != nil {
23 return fmt.Errorf("failed to open %s: %s", filePath, err)
24 }
25 defer f.Close()
26 if _, err := f.Write(d); err != nil {
27 return fmt.Errorf("failed to write %s: %s", filePath, err)
28 }
29 return nil
30 }
OLDNEW
« no previous file with comments | « client/cmd/isolate/batch_archive.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698