Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate ReadFileBytes utility code and check for string zero value #48

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/cla/consent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@
email: [email protected]
- name: Peter Oettig
email: [email protected]
- name: Phil Porada
email: [email protected]

43 changes: 0 additions & 43 deletions internal/utils/file.go

This file was deleted.

13 changes: 7 additions & 6 deletions pkg/identity/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ package identity
import (
"encoding/json"
"fmt"
"github.com/greenpau/go-authcrunch/internal/utils"
"github.com/greenpau/go-authcrunch/pkg/errors"
"github.com/greenpau/go-authcrunch/pkg/requests"
"github.com/greenpau/go-authcrunch/pkg/util"
"github.com/greenpau/versioned"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/greenpau/go-authcrunch/pkg/errors"
"github.com/greenpau/go-authcrunch/pkg/requests"
"github.com/greenpau/go-authcrunch/pkg/util"
fileutil "github.com/greenpau/go-authcrunch/pkg/util/file"
"github.com/greenpau/versioned"
)

var (
Expand Down Expand Up @@ -142,7 +143,7 @@ func NewDatabase(fp string) (*Database, error) {
if fileInfo.IsDir() {
return nil, errors.ErrNewDatabase.WithArgs(fp, "path points to a directory")
}
b, err := utils.ReadFileBytes(fp)
b, err := fileutil.ReadFileBytes(fp)
if err != nil {
return nil, errors.ErrNewDatabase.WithArgs(fp, err)
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/util/file/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package file
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -80,6 +81,9 @@ func ReadFile(filePath string) (string, error) {
}

func expandHomePath(fp string) (string, error) {
if fp == "" {
return fp, fmt.Errorf("cannot expand an empty string")
}
if fp[0] != '~' {
return fp, nil
}
Expand All @@ -93,8 +97,10 @@ func expandHomePath(fp string) (string, error) {

// ReadFileBytes expands home directory and reads a file.
func ReadFileBytes(fp string) ([]byte, error) {
var err error
fp, err = expandHomePath(fp)
if fp == "" {
return nil, fmt.Errorf("cannot expand an empty string")
}
fp, err := expandHomePath(fp)
if err != nil {
return nil, err
}
Expand Down