Skip to content

Commit

Permalink
rmv: ReadCloser Function From io Package
Browse files Browse the repository at this point in the history
The function was deprecated in favor of NewReadCloser.

BREAKING CHANGE
  • Loading branch information
b01 committed Feb 2, 2024
1 parent bc849fa commit d146d25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
16 changes: 0 additions & 16 deletions io/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ import (
"os"
)

// ReadCloser Return an io.ReadCloser from a string or filepath.
//
// Deprecated This was quickly added and now is replaced to add a new feature.
// Use NewReadCloser as a replacement since it add the feature to indicate if
// the content is a string to be used in the buffer or a path to a file to load
// into the buffer.
func ReadCloser(filepath string) (io.ReadCloser, error) {
b, e := os.ReadFile(filepath)

if e != nil {
return nil, fmt.Errorf("could not read %s: %v", filepath, e.Error())
}

return io.NopCloser(bytes.NewBuffer(b)), nil
}

// NewReadCloser Return an io.ReadCloser from a string or content from a file.
func NewReadCloser(content string, isFile bool) (io.ReadCloser, error) {
if isFile {
Expand Down
14 changes: 8 additions & 6 deletions io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (

func TestReadCloser(t *testing.T) {
tests := []struct {
name string
filepath string
want string
wantErr bool
name string
content string
isFile bool
want string
wantErr bool
}{
{"can-read-file", "testdata/salam.txt", "Salam", false},
{"can-read-file", "testdata/salam.txt", true, "Salam", false},
{"can-read-file", "Salam", false, "Salam", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ReadCloser(tt.filepath)
got, err := NewReadCloser(tt.content, tt.isFile)

if (err != nil) != tt.wantErr {
t.Errorf("ReadCloser() error = %v, wantErr %v", err, tt.wantErr)
Expand Down

0 comments on commit d146d25

Please sign in to comment.