From 29b5be9cdc78f30085e69846d42a4bb9a96b09fd Mon Sep 17 00:00:00 2001 From: Andre Soares Date: Fri, 26 Jun 2020 15:22:04 -0300 Subject: [PATCH 1/5] Rename and implement int-able without quotes --- README.md | 14 +++++++------- autoload/autoload.go | 4 ++-- cmd/godotenv/cmd.go | 2 +- go.mod | 3 +++ godotenv.go | 9 +++++++-- godotenv_test.go | 3 ++- 6 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 go.mod diff --git a/README.md b/README.md index d5370ec..f9363c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GoDotEnv [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4?svg=true)](https://ci.appveyor.com/project/joho/godotenv) [![Go Report Card](https://goreportcard.com/badge/github.com/joho/godotenv)](https://goreportcard.com/report/github.com/joho/godotenv) +# GoDotEnv [![Build Status](https://travis-ci.org/mniak/godotenv.svg?branch=master)](https://travis-ci.org/mniak/godotenv) [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4?svg=true)](https://ci.appveyor.com/project/mniak/godotenv) [![Go Report Card](https://goreportcard.com/badge/github.com/mniak/godotenv)](https://goreportcard.com/report/github.com/mniak/godotenv) A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file) @@ -17,12 +17,12 @@ There is test coverage and CI for both linuxish and windows environments, but I As a library ```shell -go get github.com/joho/godotenv +go get github.com/mniak/godotenv ``` or if you want to use it as a bin command ```shell -go get github.com/joho/godotenv/cmd/godotenv +go get github.com/mniak/godotenv/cmd/godotenv ``` ## Usage @@ -40,7 +40,7 @@ Then in your Go app you can do something like package main import ( - "github.com/joho/godotenv" + "github.com/mniak/godotenv" "log" "os" ) @@ -61,7 +61,7 @@ func main() { If you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import ```go -import _ "github.com/joho/godotenv/autoload" +import _ "github.com/mniak/godotenv/autoload" ``` While `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit @@ -177,11 +177,11 @@ Contributions are most welcome! The parser itself is pretty stupidly naive and I Releases should follow [Semver](http://semver.org/) though the first couple of releases are `v1` and `v1.1`. -Use [annotated tags for all releases](https://github.com/joho/godotenv/issues/30). Example `git tag -a v1.2.1` +Use [annotated tags for all releases](https://github.com/mniak/godotenv/issues/30). Example `git tag -a v1.2.1` ## CI -Linux: [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) Windows: [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4)](https://ci.appveyor.com/project/joho/godotenv) +Linux: [![Build Status](https://travis-ci.org/mniak/godotenv.svg?branch=master)](https://travis-ci.org/mniak/godotenv) Windows: [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4)](https://ci.appveyor.com/project/mniak/godotenv) ## Who? diff --git a/autoload/autoload.go b/autoload/autoload.go index fbcd2bd..e5b43a0 100644 --- a/autoload/autoload.go +++ b/autoload/autoload.go @@ -3,12 +3,12 @@ package autoload /* You can just read the .env file on import just by doing - import _ "github.com/joho/godotenv/autoload" + import _ "github.com/mniak/godotenv/autoload" And bob's your mother's brother */ -import "github.com/joho/godotenv" +import "github.com/mniak/godotenv" func init() { godotenv.Load() diff --git a/cmd/godotenv/cmd.go b/cmd/godotenv/cmd.go index 8dce420..f0fe5be 100644 --- a/cmd/godotenv/cmd.go +++ b/cmd/godotenv/cmd.go @@ -7,7 +7,7 @@ import ( "strings" - "github.com/joho/godotenv" + "github.com/mniak/godotenv" ) func main() { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9d6254c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/mniak/godotenv + +go 1.14 diff --git a/godotenv.go b/godotenv.go index 69e816c..50d97bd 100644 --- a/godotenv.go +++ b/godotenv.go @@ -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 diff --git a/godotenv_test.go b/godotenv_test.go index d1f73cb..17dc243 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -445,7 +445,8 @@ func TestWrite(t *testing.T) { writeAndCompare(`foo="\n\r\\r!"`, `foo="\n\r\\r\!"`) // lines should be sorted writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"") - + // integers should not be quoted + writeAndCompare(`key="10"`, `key=10`) } func TestRoundtrip(t *testing.T) { From 63ea8bf09bd4505f4cdcbb4f5f522f26c5d58adf Mon Sep 17 00:00:00 2001 From: Andre Soares Date: Fri, 26 Jun 2020 15:35:47 -0300 Subject: [PATCH 2/5] Change package name back to joho/godotenv --- README.md | 14 +++++++------- autoload/autoload.go | 4 ++-- cmd/godotenv/cmd.go | 2 +- go.mod | 4 +++- godotenv.go | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f9363c7..d5370ec 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GoDotEnv [![Build Status](https://travis-ci.org/mniak/godotenv.svg?branch=master)](https://travis-ci.org/mniak/godotenv) [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4?svg=true)](https://ci.appveyor.com/project/mniak/godotenv) [![Go Report Card](https://goreportcard.com/badge/github.com/mniak/godotenv)](https://goreportcard.com/report/github.com/mniak/godotenv) +# GoDotEnv [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4?svg=true)](https://ci.appveyor.com/project/joho/godotenv) [![Go Report Card](https://goreportcard.com/badge/github.com/joho/godotenv)](https://goreportcard.com/report/github.com/joho/godotenv) A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file) @@ -17,12 +17,12 @@ There is test coverage and CI for both linuxish and windows environments, but I As a library ```shell -go get github.com/mniak/godotenv +go get github.com/joho/godotenv ``` or if you want to use it as a bin command ```shell -go get github.com/mniak/godotenv/cmd/godotenv +go get github.com/joho/godotenv/cmd/godotenv ``` ## Usage @@ -40,7 +40,7 @@ Then in your Go app you can do something like package main import ( - "github.com/mniak/godotenv" + "github.com/joho/godotenv" "log" "os" ) @@ -61,7 +61,7 @@ func main() { If you're even lazier than that, you can just take advantage of the autoload package which will read in `.env` on import ```go -import _ "github.com/mniak/godotenv/autoload" +import _ "github.com/joho/godotenv/autoload" ``` While `.env` in the project root is the default, you don't have to be constrained, both examples below are 100% legit @@ -177,11 +177,11 @@ Contributions are most welcome! The parser itself is pretty stupidly naive and I Releases should follow [Semver](http://semver.org/) though the first couple of releases are `v1` and `v1.1`. -Use [annotated tags for all releases](https://github.com/mniak/godotenv/issues/30). Example `git tag -a v1.2.1` +Use [annotated tags for all releases](https://github.com/joho/godotenv/issues/30). Example `git tag -a v1.2.1` ## CI -Linux: [![Build Status](https://travis-ci.org/mniak/godotenv.svg?branch=master)](https://travis-ci.org/mniak/godotenv) Windows: [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4)](https://ci.appveyor.com/project/mniak/godotenv) +Linux: [![Build Status](https://travis-ci.org/joho/godotenv.svg?branch=master)](https://travis-ci.org/joho/godotenv) Windows: [![Build status](https://ci.appveyor.com/api/projects/status/9v40vnfvvgde64u4)](https://ci.appveyor.com/project/joho/godotenv) ## Who? diff --git a/autoload/autoload.go b/autoload/autoload.go index e5b43a0..fbcd2bd 100644 --- a/autoload/autoload.go +++ b/autoload/autoload.go @@ -3,12 +3,12 @@ package autoload /* You can just read the .env file on import just by doing - import _ "github.com/mniak/godotenv/autoload" + import _ "github.com/joho/godotenv/autoload" And bob's your mother's brother */ -import "github.com/mniak/godotenv" +import "github.com/joho/godotenv" func init() { godotenv.Load() diff --git a/cmd/godotenv/cmd.go b/cmd/godotenv/cmd.go index f0fe5be..2365f70 100644 --- a/cmd/godotenv/cmd.go +++ b/cmd/godotenv/cmd.go @@ -7,7 +7,7 @@ import ( "strings" - "github.com/mniak/godotenv" + "github.com/joho/godotenv/godotenv" ) func main() { diff --git a/go.mod b/go.mod index 9d6254c..da7f8d4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ -module github.com/mniak/godotenv +module github.com/joho/godotenv/godotenv go 1.14 + +require github.com/joho/godotenv v1.3.0 // indirect diff --git a/godotenv.go b/godotenv.go index 50d97bd..175bd93 100644 --- a/godotenv.go +++ b/godotenv.go @@ -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/mniak/godotenv +// Examples/readme can be found on the github page at https://github.com/joho/godotenv/godotenv // // The TL;DR is that you make a .env file that looks something like // From f4e7418908ad3626296c9b7adb6f546a5f1acb78 Mon Sep 17 00:00:00 2001 From: Andre Soares Date: Fri, 26 Jun 2020 15:36:35 -0300 Subject: [PATCH 3/5] Remove go.mod --- go.mod | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 go.mod diff --git a/go.mod b/go.mod deleted file mode 100644 index da7f8d4..0000000 --- a/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/joho/godotenv/godotenv - -go 1.14 - -require github.com/joho/godotenv v1.3.0 // indirect From fccdfd265d3ed85f5554c01eaf817b21d4f283e4 Mon Sep 17 00:00:00 2001 From: Andre Soares Date: Fri, 26 Jun 2020 15:39:06 -0300 Subject: [PATCH 4/5] Fix package name --- cmd/godotenv/cmd.go | 2 +- godotenv.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/godotenv/cmd.go b/cmd/godotenv/cmd.go index 2365f70..8dce420 100644 --- a/cmd/godotenv/cmd.go +++ b/cmd/godotenv/cmd.go @@ -7,7 +7,7 @@ import ( "strings" - "github.com/joho/godotenv/godotenv" + "github.com/joho/godotenv" ) func main() { diff --git a/godotenv.go b/godotenv.go index 175bd93..8e311f4 100644 --- a/godotenv.go +++ b/godotenv.go @@ -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/godotenv +// Examples/readme can be found on the github page at https://github.com/joho/godotenv // // The TL;DR is that you make a .env file that looks something like // From 6e653f9adfb8c2ae280cb0b3082f6a596e51ec40 Mon Sep 17 00:00:00 2001 From: Andre Soares Date: Fri, 26 Jun 2020 15:39:50 -0300 Subject: [PATCH 5/5] add newline back --- godotenv_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/godotenv_test.go b/godotenv_test.go index 17dc243..7274c14 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -447,6 +447,7 @@ func TestWrite(t *testing.T) { writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"") // integers should not be quoted writeAndCompare(`key="10"`, `key=10`) + } func TestRoundtrip(t *testing.T) {