diff --git a/godotenv.go b/godotenv.go index de2ff39..2710572 100644 --- a/godotenv.go +++ b/godotenv.go @@ -122,8 +122,8 @@ func Parse(r io.Reader) (envMap map[string]string, err error) { return } -//ParseString reads an env file from a string, returning a map of keys and values. -func ParseString(str string) (envMap map[string]string, err error) { +//Unmarshal reads an env file from a string, returning a map of keys and values. +func Unmarshal(str string) (envMap map[string]string, err error) { return Parse(strings.NewReader(str)) } @@ -146,7 +146,7 @@ func Exec(filenames []string, cmd string, cmdArgs []string) error { // Write serializes the given environment and writes it to a file func Write(envMap map[string]string, filename string) error { - content, error := WriteString(envMap) + content, error := Marshal(envMap) if error != nil { return error } @@ -158,10 +158,9 @@ func Write(envMap map[string]string, filename string) error { return err } -// WriteString outputs the given environment as a dotenv-formatted environment file. -// +// Marshal outputs the given environment as a dotenv-formatted environment file. // Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped. -func WriteString(envMap map[string]string) (string, error) { +func Marshal(envMap map[string]string) (string, error) { lines := make([]string, 0, len(envMap)) for k, v := range envMap { lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v))) diff --git a/godotenv_test.go b/godotenv_test.go index 22e8f8b..47b0c35 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -331,8 +331,8 @@ func TestErrorParsing(t *testing.T) { func TestWrite(t *testing.T) { writeAndCompare := func(env string, expected string) { - envMap, _ := ParseString(env) - actual, _ := WriteString(envMap) + envMap, _ := Unmarshal(env) + actual, _ := Marshal(envMap) if expected != actual { t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual) } @@ -358,11 +358,11 @@ func TestRoundtrip(t *testing.T) { if err != nil { continue } - rep, err := WriteString(env) + rep, err := Marshal(env) if err != nil { continue } - roundtripped, err := ParseString(rep) + roundtripped, err := Unmarshal(rep) if err != nil { continue }