Rename and implement int-able without quotes

This commit is contained in:
Andre Soares
2020-06-26 15:22:04 -03:00
parent d6ee6871f2
commit 29b5be9cdc
6 changed files with 22 additions and 13 deletions

View File

@ -1,6 +1,6 @@
// Package godotenv is a go port of the ruby dotenv library (https://github.com/bkeepers/dotenv)
//
// Examples/readme can be found on the github page at https://github.com/joho/godotenv
// Examples/readme can be found on the github page at https://github.com/mniak/godotenv
//
// The TL;DR is that you make a .env file that looks something like
//
@ -22,6 +22,7 @@ import (
"os/exec"
"regexp"
"sort"
"strconv"
"strings"
)
@ -169,7 +170,11 @@ func Write(envMap map[string]string, filename 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)))
if d, err := strconv.Atoi(v); err == nil {
lines = append(lines, fmt.Sprintf(`%s=%d`, k, d))
} else {
lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
}
}
sort.Strings(lines)
return strings.Join(lines, "\n"), nil