Skip to content

Commit

Permalink
Fixing bugs: missing newline, shameful errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Byrd committed Jan 9, 2016
1 parent 8027d66 commit 42d3cf7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 llya Kowalewski
Copyright (c) 2015 Ian Byrd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![GoDoc](https://godoc.org/github.com/tucnak/store?status.svg)](https://godoc.org/github.com/tucnak/store)

I didn't like existing configuration management solution, like [globalconf](https://github.com/rakyll/globalconf), [tachyon](https://github.com/vektra/tachyon) or [viper](https://github.com/spf13/viper). First two just don't feel right and viper, imo, a little overcomplicated—definitely too much for small projects.
I didn't like existing configuration management solutions like [globalconf](https://github.com/rakyll/globalconf), [tachyon](https://github.com/vektra/tachyon) or [viper](https://github.com/spf13/viper). First two just don't feel right and viper, imo, a little overcomplicated—definitely too much for small projects.

Store currenty supports JSON and TOML and I am not planning to add support for other file formats soon.

Expand Down
9 changes: 0 additions & 9 deletions errors.go

This file was deleted.

16 changes: 7 additions & 9 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Load(path string, v interface{}) error {
return err
}
} else {
return &stringError{"unknown configuration format"}
return fmt.Errorf("store: unknown configuration format")
}

return nil
Expand All @@ -82,35 +82,33 @@ func Save(path string, v interface{}) error {
panic("store: application name not defined")
}

var data []byte
var b bytes.Buffer

if strings.HasSuffix(path, ".toml") {
var b bytes.Buffer

encoder := toml.NewEncoder(&b)
if err := encoder.Encode(v); err != nil {
return nil
}

data = b.Bytes()
} else if strings.HasSuffix(path, ".json") {
fileData, err := json.Marshal(v)

if err != nil {
return err
}

data = fileData
b.Write(fileData)
} else {
return &stringError{"unknown configuration format"}
return fmt.Errorf("unknown configuration format")
}

b.WriteRune('\n')

globalPath := buildPlatformPath(path)
if err := os.MkdirAll(filepath.Dir(globalPath), os.ModePerm); err != nil {
return err
}

if err := ioutil.WriteFile(globalPath, data, os.ModePerm); err != nil {
if err := ioutil.WriteFile(globalPath, b.Bytes(), os.ModePerm); err != nil {
return err
}

Expand Down

0 comments on commit 42d3cf7

Please sign in to comment.