diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-08-24 09:50:31 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-08-24 09:50:31 +0200 |
commit | 4478aeeb245a208c8e4a4c4c9d217136de03f609 (patch) | |
tree | 7802cf81a50c8c714b504b1d5611d619df50357f /client/go/util/io.go | |
parent | 89dac5ccb4b9fd1f34c28338b2ed01e87a80c630 (diff) |
Move modules to root
Diffstat (limited to 'client/go/util/io.go')
-rw-r--r-- | client/go/util/io.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/go/util/io.go b/client/go/util/io.go new file mode 100644 index 00000000000..217beb085d1 --- /dev/null +++ b/client/go/util/io.go @@ -0,0 +1,31 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// File utilities. +// Author: bratseth + +package util + +import ( + "errors" + "io" + "os" + "strings" +) + +// Returns true if the given path exists +func PathExists(path string) bool { + _, err := os.Stat(path) + return ! errors.Is(err, os.ErrNotExist) +} + +// Returns true is the given path points to an existing directory +func IsDirectory(path string) bool { + info, err := os.Stat(path) + return ! errors.Is(err, os.ErrNotExist) && info.IsDir() +} + +// Returns the content of a reader as a string +func ReaderToString(reader io.ReadCloser) string { + buffer := new(strings.Builder) + io.Copy(buffer, reader) + return buffer.String() +}
\ No newline at end of file |