Skip to content

Commit

Permalink
minor:
Browse files Browse the repository at this point in the history
ref: #67, v0.9.0
desc:
- added findAllEnvFiles(), pass to Initiate() to allow any .env file name convention to work
  • Loading branch information
samjtro committed Oct 29, 2024
1 parent 67452aa commit 1853b83
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
"strings"
"time"

Expand All @@ -30,7 +32,7 @@ type DB struct {
var Tokens DB

func init() {
err := godotenv.Load()
err := godotenv.Load(findAllEnvFiles()...)
isErrNil(err)
}

Expand All @@ -41,6 +43,25 @@ func isErrNil(err error) {
}
}

// find all env files
func findAllEnvFiles() []string {
var files []string
err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
split := strings.Split(d.Name(), ".")
if len(split) > 1 {
if split[1] == "env" {
files = append(files, d.Name())
}
}
return err
})
isErrNil(err)
return files
}

// wrapper for os.UserHomeDir()
func homeDir() string {
dir, err := os.UserHomeDir()
Expand Down

0 comments on commit 1853b83

Please sign in to comment.