<commit_before>package env

import (
	"io/ioutil"
	"os"

	"github.com/blang/vfs"
)

// Getenv - retrieves the value of the environment variable named by the key.
// If the variable is unset, but the same variable ending in `_FILE` is set, the
// referenced file will be read into the value.
// Otherwise the provided default (or an emptry string) is returned.
func Getenv(key string, def ...string) string {
	return GetenvVFS(vfs.OS(), key, def...)
}

// GetenvVFS - a convenience function intended for internal use only!
func GetenvVFS(fs vfs.Filesystem, key string, def ...string) string {
	val := getenvFile(fs, key)
	if val == "" && len(def) > 0 {
		return def[0]
	}

	return val
}

func getenvFile(fs vfs.Filesystem, key string) string {
	val := os.Getenv(key)
	if val != "" {
		return val
	}

	p := os.Getenv(key + "_FILE")
	if p != "" {
		val, err := readFile(fs, p)
		if err != nil {
			return ""
		}
		return val
	}

	return ""
}

func readFile(fs vfs.Filesystem, p string) (string, error) {
	f, err := fs.OpenFile(p, os.O_RDONLY, 0)
	if err != nil {
		return "", err<commit_msg>Remove trailing spaces<commit_after>package env

import (
	"io/ioutil"
	"os"
	"strings"

	"github.com/blang/vfs"
)

// Getenv - retrieves the value of the environment variable named by the key.
// If the variable is unset, but the same variable ending in `_FILE` is set, the
// referenced file will be read into the value.
// Otherwise the provided default (or an emptry string) is returned.
func Getenv(key string, def ...string) string {
	return GetenvVFS(vfs.OS(), key, def...)
}

// GetenvVFS - a convenience function intended for internal use only!
func GetenvVFS(fs vfs.Filesystem, key string, def ...string) string {
	val := getenvFile(fs, key)
	if val == "" && len(def) > 0 {
		return def[0]
	}

	return val
}

func getenvFile(fs vfs.Filesystem, key string) string {
	val := os.Getenv(key)
	if val != "" {
		return val
	}

	p := os.Getenv(key + "_FILE")
	if p != "" {
		val, err := readFile(fs, p)
		if err != nil {
			return ""
		}
		return strings.TrimSpace(val)
	}

	return ""
}

func readFile(fs vfs.Filesystem, p string) (string, error) {
	f, err := fs.OpenFile(p, os.O_RDONLY, 0)
	if err != nil {
		return "", err
{'fraction_non_alphanumeric': 0.13860045146726863, 'fraction_numerical': 0.002708803611738149, 'mean_word_length': 3.277992277992278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5948129', 'n_tokens_mistral': 821, 'n_tokens_neox': 789, 'n_words': 270}