From 381bfaa691ebf7a134ee9382b1f1138b4b7794be Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet <juan@benet.ai> Date: Sat, 5 Jul 2014 01:52:05 -0700 Subject: [PATCH] gofmt --- config/config.go | 71 +++++++++++++++++++++---------------------- config/config_test.go | 16 +++++----- config/serialize.go | 40 ++++++++++++------------ 3 files changed, 63 insertions(+), 64 deletions(-) diff --git a/config/config.go b/config/config.go index c09913603..4797bf605 100644 --- a/config/config.go +++ b/config/config.go @@ -1,26 +1,25 @@ package config import ( - "strings" - "os" - "os/user" + "os" + "os/user" + "strings" ) type Identity struct { - PeerId string + PeerId string } type Datastore struct { - Type string - Path string + Type string + Path string } type Config struct { - Identity Identity - Datastore Datastore + Identity Identity + Datastore Datastore } - var defaultConfigFilePath = "~/.go-ipfs/config" var defaultConfigFile = `{ "identity": {}, @@ -32,31 +31,31 @@ var defaultConfigFile = `{ ` func LoadConfig(filename string) (*Config, error) { - if len(filename) == 0 { - filename = defaultConfigFilePath - } - - // expand ~/ - if strings.HasPrefix(filename, "~/") { - usr, err := user.Current() - if err != nil { - return nil, err - } - - dir := usr.HomeDir + "/" - filename = strings.Replace(filename, "~/", dir, 1) - } - - // if nothing is there, write first conifg file. - if _, err := os.Stat(filename); os.IsNotExist(err) { - WriteFile(filename, []byte(defaultConfigFile)) - } - - var cfg Config - err := ReadConfigFile(filename, &cfg) - if err != nil { - return nil, err - } - - return &cfg, err + if len(filename) == 0 { + filename = defaultConfigFilePath + } + + // expand ~/ + if strings.HasPrefix(filename, "~/") { + usr, err := user.Current() + if err != nil { + return nil, err + } + + dir := usr.HomeDir + "/" + filename = strings.Replace(filename, "~/", dir, 1) + } + + // if nothing is there, write first conifg file. + if _, err := os.Stat(filename); os.IsNotExist(err) { + WriteFile(filename, []byte(defaultConfigFile)) + } + + var cfg Config + err := ReadConfigFile(filename, &cfg) + if err != nil { + return nil, err + } + + return &cfg, err } diff --git a/config/config_test.go b/config/config_test.go index b293255d4..25236e071 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1,17 +1,17 @@ package config import ( - "fmt" - "testing" + "fmt" + "testing" ) func TestConfig(t *testing.T) { - cfg, err := LoadConfig("") - if err != nil { - t.Error(err) - return - } + cfg, err := LoadConfig("") + if err != nil { + t.Error(err) + return + } - fmt.Printf(cfg.Datastore.Path) + fmt.Printf(cfg.Datastore.Path) } diff --git a/config/serialize.go b/config/serialize.go index c906eb6cd..e5c9e0855 100644 --- a/config/serialize.go +++ b/config/serialize.go @@ -1,39 +1,39 @@ package config import ( - "os" - "path" - "io/ioutil" - "encoding/json" + "encoding/json" + "io/ioutil" + "os" + "path" ) func ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) + return ioutil.ReadFile(filename) } func WriteFile(filename string, buf []byte) error { - err := os.MkdirAll(path.Dir(filename), 0777) - if err != nil { - return err - } + err := os.MkdirAll(path.Dir(filename), 0777) + if err != nil { + return err + } - return ioutil.WriteFile(filename, buf, 0666) + return ioutil.WriteFile(filename, buf, 0666) } func ReadConfigFile(filename string, cfg *Config) error { - buf, err := ReadFile(filename) - if err != nil { - return err - } + buf, err := ReadFile(filename) + if err != nil { + return err + } - return json.Unmarshal(buf, cfg) + return json.Unmarshal(buf, cfg) } func WriteConfigFile(filename string, cfg *Config) error { - buf, err := json.MarshalIndent(cfg, "", " ") - if err != nil { - return err - } + buf, err := json.MarshalIndent(cfg, "", " ") + if err != nil { + return err + } - return WriteFile(filename, buf) + return WriteFile(filename, buf) } -- GitLab