Skip to content

Commit 42d3cf7

Browse files
author
Ian Byrd
committed
Fixing bugs: missing newline, shameful errors
1 parent 8027d66 commit 42d3cf7

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 llya Kowalewski
3+
Copyright (c) 2015 Ian Byrd
44

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
[![GoDoc](https://godoc.org/github.com/tucnak/store?status.svg)](https://godoc.org/github.com/tucnak/store)
55

6-
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.
6+
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.
77

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

errors.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

store.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Load(path string, v interface{}) error {
6767
return err
6868
}
6969
} else {
70-
return &stringError{"unknown configuration format"}
70+
return fmt.Errorf("store: unknown configuration format")
7171
}
7272

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

85-
var data []byte
85+
var b bytes.Buffer
8686

8787
if strings.HasSuffix(path, ".toml") {
88-
var b bytes.Buffer
89-
9088
encoder := toml.NewEncoder(&b)
9189
if err := encoder.Encode(v); err != nil {
9290
return nil
9391
}
9492

95-
data = b.Bytes()
9693
} else if strings.HasSuffix(path, ".json") {
9794
fileData, err := json.Marshal(v)
98-
9995
if err != nil {
10096
return err
10197
}
10298

103-
data = fileData
99+
b.Write(fileData)
104100
} else {
105-
return &stringError{"unknown configuration format"}
101+
return fmt.Errorf("unknown configuration format")
106102
}
107103

104+
b.WriteRune('\n')
105+
108106
globalPath := buildPlatformPath(path)
109107
if err := os.MkdirAll(filepath.Dir(globalPath), os.ModePerm); err != nil {
110108
return err
111109
}
112110

113-
if err := ioutil.WriteFile(globalPath, data, os.ModePerm); err != nil {
111+
if err := ioutil.WriteFile(globalPath, b.Bytes(), os.ModePerm); err != nil {
114112
return err
115113
}
116114

0 commit comments

Comments
 (0)