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:
parent
f978e42036
commit
a1ccf18172
1 changed files with 4 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue