1
0
Fork 0
mirror of https://github.com/tmrts/go-patterns.git synced 2025-04-03 13:13:34 +03:00

functional-options.go: Make file.New implementation match usage example

This commit is contained in:
chris erway 2017-12-13 18:00:28 -05:00
parent f978e42036
commit a1ccf18172

View file

@ -50,7 +50,7 @@ func Permissions(perms os.FileMode) Option {
```go
package file
func New(filepath string, setters ...Option) error {
func New(filepath string, setters ...Option) (*os.File, error) {
// Default Options
args := &Options{
UID: os.Getuid(),
@ -66,16 +66,16 @@ func New(filepath string, setters ...Option) error {
f, err := os.OpenFile(filepath, args.Flags, args.Permissions)
if err != nil {
return err
return nil, err
} else {
defer f.Close()
}
if _, err := f.WriteString(args.Contents); err != nil {
return err
return nil, err
}
return f.Chown(args.UID, args.GID)
return f, f.Chown(args.UID, args.GID)
}
```