1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Replace json.Unmarshal with json.Decoder().Decode()

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca 2015-04-22 00:47:51 +02:00
parent 92f4bd59ce
commit 26543e0309
5 changed files with 24 additions and 20 deletions

View file

@ -233,7 +233,7 @@ func parseString(rest string) (*Node, map[string]bool, error) {
// parseJSON converts JSON arrays to an AST.
func parseJSON(rest string) (*Node, map[string]bool, error) {
var myJson []interface{}
if err := json.Unmarshal([]byte(rest), &myJson); err != nil {
if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJson); err != nil {
return nil, nil, err
}

View file

@ -4,7 +4,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
@ -107,12 +106,13 @@ func getArgs() *InitArgs {
func setupEnv(args *InitArgs) error {
// Get env
var env []string
content, err := ioutil.ReadFile(".dockerenv")
dockerenv, err := os.Open(".dockerenv")
if err != nil {
return fmt.Errorf("Unable to load environment variables: %v", err)
}
if err := json.Unmarshal(content, &env); err != nil {
return fmt.Errorf("Unable to unmarshal environment variables: %v", err)
defer dockerenv.Close()
if err := json.NewDecoder(dockerenv).Decode(&env); err != nil {
return fmt.Errorf("Unable to decode environment variables: %v", err)
}
// Propagate the plugin-specific container env variable
env = append(env, "container="+os.Getenv("container"))

View file

@ -58,22 +58,26 @@ func (s *TagStore) Load(inTar io.ReadCloser, outStream io.Writer) error {
}
}
repositoriesJson, err := ioutil.ReadFile(path.Join(tmpImageDir, "repo", "repositories"))
if err == nil {
repositories := map[string]Repository{}
if err := json.Unmarshal(repositoriesJson, &repositories); err != nil {
reposJSONFile, err := os.Open(path.Join(tmpImageDir, "repo", "repositories"))
if err != nil {
if !os.IsNotExist(err) {
return err
}
return nil
}
defer reposJSONFile.Close()
for imageName, tagMap := range repositories {
for tag, address := range tagMap {
if err := s.SetLoad(imageName, tag, address, true, outStream); err != nil {
return err
}
repositories := map[string]Repository{}
if err := json.NewDecoder(reposJSONFile).Decode(&repositories); err != nil {
return err
}
for imageName, tagMap := range repositories {
for tag, address := range tagMap {
if err := s.SetLoad(imageName, tag, address, true, outStream); err != nil {
return err
}
}
} else if !os.IsNotExist(err) {
return err
}
return nil

View file

@ -115,11 +115,12 @@ func (store *TagStore) save() error {
}
func (store *TagStore) reload() error {
jsonData, err := ioutil.ReadFile(store.path)
f, err := os.Open(store.path)
if err != nil {
return err
}
if err := json.Unmarshal(jsonData, store); err != nil {
defer f.Close()
if err := json.NewDecoder(f).Decode(&store); err != nil {
return err
}
return nil

View file

@ -58,8 +58,7 @@ func FromParam(p string) (Args, error) {
if len(p) == 0 {
return args, nil
}
err := json.Unmarshal([]byte(p), &args)
if err != nil {
if err := json.NewDecoder(strings.NewReader(p)).Decode(&args); err != nil {
return nil, err
}
return args, nil