Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit b1bb9d9

Browse files
committed
rename WriteString/ReadString to Marshal/Unmarshal
1 parent 5d289f4 commit b1bb9d9

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

godotenv.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func Parse(r io.Reader) (envMap map[string]string, err error) {
122122
return
123123
}
124124

125-
//ParseString reads an env file from a string, returning a map of keys and values.
126-
func ParseString(str string) (envMap map[string]string, err error) {
125+
//Unmarshal reads an env file from a string, returning a map of keys and values.
126+
func Unmarshal(str string) (envMap map[string]string, err error) {
127127
return Parse(strings.NewReader(str))
128128
}
129129

@@ -146,7 +146,7 @@ func Exec(filenames []string, cmd string, cmdArgs []string) error {
146146

147147
// Write serializes the given environment and writes it to a file
148148
func Write(envMap map[string]string, filename string) error {
149-
content, error := WriteString(envMap)
149+
content, error := Marshal(envMap)
150150
if error != nil {
151151
return error
152152
}
@@ -158,10 +158,9 @@ func Write(envMap map[string]string, filename string) error {
158158
return err
159159
}
160160

161-
// WriteString outputs the given environment as a dotenv-formatted environment file.
162-
//
161+
// Marshal outputs the given environment as a dotenv-formatted environment file.
163162
// Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped.
164-
func WriteString(envMap map[string]string) (string, error) {
163+
func Marshal(envMap map[string]string) (string, error) {
165164
lines := make([]string, 0, len(envMap))
166165
for k, v := range envMap {
167166
lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))

godotenv_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ func TestErrorParsing(t *testing.T) {
331331

332332
func TestWrite(t *testing.T) {
333333
writeAndCompare := func(env string, expected string) {
334-
envMap, _ := ParseString(env)
335-
actual, _ := WriteString(envMap)
334+
envMap, _ := Unmarshal(env)
335+
actual, _ := Marshal(envMap)
336336
if expected != actual {
337337
t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual)
338338
}
@@ -358,11 +358,11 @@ func TestRoundtrip(t *testing.T) {
358358
if err != nil {
359359
continue
360360
}
361-
rep, err := WriteString(env)
361+
rep, err := Marshal(env)
362362
if err != nil {
363363
continue
364364
}
365-
roundtripped, err := ParseString(rep)
365+
roundtripped, err := Unmarshal(rep)
366366
if err != nil {
367367
continue
368368
}

0 commit comments

Comments
 (0)