-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(must gather): better handling of auth errors
- Loading branch information
1 parent
59a73a5
commit 81e9300
Showing
7 changed files
with
248 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cmdutil | ||
|
||
import ( | ||
"bufio" | ||
"github.com/hashicorp/go-multierror" | ||
"io" | ||
"os" | ||
) | ||
|
||
type OutputWriter struct { | ||
delegate io.Writer | ||
writer *bufio.Writer | ||
mustClose bool | ||
} | ||
|
||
func NewOutputWriter(delegate io.Writer) (*OutputWriter, error) { | ||
answer := OutputWriter{ | ||
delegate: delegate, | ||
writer: bufio.NewWriter(delegate), | ||
mustClose: false, | ||
} | ||
|
||
return &answer, nil | ||
} | ||
|
||
func NewOutputFileWriter(path string) (*OutputWriter, error) { | ||
delegate, err := os.Create(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
answer := OutputWriter{ | ||
delegate: delegate, | ||
writer: bufio.NewWriter(delegate), | ||
mustClose: true, | ||
} | ||
|
||
return &answer, nil | ||
} | ||
|
||
func (in *OutputWriter) Write(p []byte) (n int, err error) { | ||
return in.writer.Write(p) | ||
} | ||
|
||
func (in *OutputWriter) Close() error { | ||
var err error | ||
|
||
if ferr := in.writer.Flush(); err != nil { | ||
err = multierror.Append(err, ferr) | ||
} | ||
|
||
if in.mustClose { | ||
if c, ok := in.delegate.(io.Closer); ok { | ||
if cerr := c.Close(); cerr != nil { | ||
err = multierror.Append(err, cerr) | ||
} | ||
} | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.