From a1ccf1817202c47101931e74af4623291e3b529a Mon Sep 17 00:00:00 2001 From: chris erway Date: Wed, 13 Dec 2017 18:00:28 -0500 Subject: [PATCH] functional-options.go: Make file.New implementation match usage example --- idiom/functional-options.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/idiom/functional-options.md b/idiom/functional-options.md index 1e95086..dea4974 100644 --- a/idiom/functional-options.md +++ b/idiom/functional-options.md @@ -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) } ```