// KeyValuesFromLine returns a kv with blank key if the line is empty or a comment.
// The value will be retrieved from the environment if necessary.
KeyValuesFromLine returns a kv with blank key if the line is empty or a comment.
The value will be retrieved from the environment if necessary.
// KeyValuesFromLine returns a kv with blank key if the line is empty or a comment . // The value will be retrieved from the environment if necessary .
func (fl *fileLoader) keyValuesFromLine(line []byte, currentLine int) (types.Pair, error) {
	kv := types.Pair{}
	if !utf8.Valid(line) {
		return kv, fmt.Errorf("line %d has invalid utf8 bytes : %v", line, string(line))
	}
	if currentLine == 0 {
		line = bytes.TrimPrefix(line, utf8bom)
	}
	line = bytes.TrimLeftFunc(line, unicode.IsSpace)
	if len(line) == 0 || line[0] == '#' {
		return kv, nil
	}
	data := strings.SplitN(string(line), "=", 2)
	key := data[0]
	if err := fl.validator.IsEnvVarName(key); err != nil {
		return kv, err
	}
	if len(data) == 2 {
		kv.Value = data[1]
	} else {
		kv.Value = os.Getenv(key)
	}
	kv.Key = key
	return kv, nil
}
func ( fl * fileLoader ) keyValuesFromLine ( line [ ] byte , currentLine int ) ( types . Pair , error ) { kv := types . Pair { } if ! utf8 . Valid ( line ) { return kv , fmt . Errorf ( " " , line , string ( line ) ) } if currentLine == 0 { line = bytes . TrimPrefix ( line , utf8bom ) } line = bytes . TrimLeftFunc ( line , unicode . IsSpace ) if len ( line ) == 0 || line [ 0 ] == '#' { return kv , nil } data := strings . SplitN ( string ( line ) , " " , 2 ) key := data [ 0 ] if err := fl . validator . IsEnvVarName ( key ) ; err != nil { return kv , err } if len ( data ) == 2 { kv . Value = data [ 1 ] } else { kv . Value = os . Getenv ( key ) } kv . Key = key return kv , nil }
KeyValuesFromLine returns a kv with blank key if the line is empty or a comment.
KeyValuesFromLine returns a kv with blank key if the line is empty or a comment .
// We trim UTF8 BOM from the first line of the file but no others // trim the line from all leading whitespace first // If the line is empty or a comment, we return a blank key/value pair. // No value (no `=` in the line) is a signal to obtain the value // from the environment.