From 5aa4a794752338360491203408ca5a4f3c2c3d52 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 9 Oct 2022 13:40:29 +0800 Subject: [PATCH] up: breaking - remove all on pkg dotnev, please use gookit/ini/v2/dotenv --- dotnev/README.md | 13 ------ dotnev/dotenv.go | 63 --------------------------- dotnev/dotenv_test.go | 90 --------------------------------------- dotnev/testdata/.env | 2 - dotnev/testdata/error.ini | 2 - 5 files changed, 170 deletions(-) delete mode 100644 dotnev/dotenv_test.go delete mode 100644 dotnev/testdata/.env delete mode 100644 dotnev/testdata/error.ini diff --git a/dotnev/README.md b/dotnev/README.md index d5cc9e1..2164964 100644 --- a/dotnev/README.md +++ b/dotnev/README.md @@ -2,16 +2,3 @@ Package `dotenv` that supports importing data from files (eg `.env`) to ENV -## Usage - -```go -err := dotenv.Load("./", ".env") -// err := dotenv.LoadExists("./", ".env") - -val := dotenv.Get("ENV_KEY") -// Or use -// val := os.Getenv("ENV_KEY") - -// with default value -val := dotenv.Get("ENV_KEY", "default value") -``` diff --git a/dotnev/dotenv.go b/dotnev/dotenv.go index fe51f56..4620cfb 100644 --- a/dotnev/dotenv.go +++ b/dotnev/dotenv.go @@ -2,66 +2,3 @@ // // Deprecated: please use github.com/gookit/ini/v2/dotenv package dotnev - -import ( - "github.com/gookit/ini/v2/dotenv" -) - -// LoadedData get all loaded data by dontenv -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func LoadedData() map[string]string { - return dotenv.LoadedData() -} - -// ClearLoaded clear the previously set ENV value -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func ClearLoaded() { - dotenv.ClearLoaded() -} - -// DontUpperEnvKey don't change key to upper on set ENV -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func DontUpperEnvKey() { - dotenv.DontUpperEnvKey() -} - -// Load parse .env file data to os ENV. -// -// Usage: -// -// dotenv.Load("./", ".env") -// -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func Load(dir string, filenames ...string) (err error) { - return dotenv.Load(dir, filenames...) -} - -// LoadExists only load on file exists -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func LoadExists(dir string, filenames ...string) error { - return dotenv.LoadExists(dir, filenames...) -} - -// LoadFromMap load data from given string map -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func LoadFromMap(kv map[string]string) (err error) { - return dotenv.LoadFromMap(kv) -} - -// Get get os ENV value by name -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func Get(name string, defVal ...string) (val string) { - return dotenv.Get(name, defVal...) -} - -// Bool get a bool value by key -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func Bool(name string, defVal ...bool) (val bool) { - return dotenv.Bool(name, defVal...) -} - -// Int get a int value by key -// Deprecated: please use github.com/gookit/ini/v2/dotenv -func Int(name string, defVal ...int) (val int) { - return dotenv.Int(name, defVal...) -} diff --git a/dotnev/dotenv_test.go b/dotnev/dotenv_test.go deleted file mode 100644 index 804e36d..0000000 --- a/dotnev/dotenv_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package dotnev - -import ( - "fmt" - "os" - "runtime" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestLoad(t *testing.T) { - err := Load("./testdata", "not-exist", ".env") - assert.Error(t, err) - - assert.Equal(t, "", os.Getenv("DONT_ENV_TEST")) - - err = Load("./testdata") - assert.NoError(t, err) - assert.Equal(t, "blog", os.Getenv("DONT_ENV_TEST")) - assert.Equal(t, "blog", Get("DONT_ENV_TEST")) - _ = os.Unsetenv("DONT_ENV_TEST") // clear - - err = Load("./testdata", "error.ini") - assert.Error(t, err) - - err = Load("./testdata", "invalid_key.ini") - assert.Error(t, err) - - assert.Equal(t, "def-val", Get("NOT-EXIST", "def-val")) - - ClearLoaded() -} - -func TestLoadExists(t *testing.T) { - assert.Equal(t, "", os.Getenv("DONT_ENV_TEST")) - - err := LoadExists("./testdata", "not-exist", ".env") - - assert.NoError(t, err) - assert.Equal(t, "blog", os.Getenv("DONT_ENV_TEST")) - assert.Equal(t, "blog", Get("DONT_ENV_TEST")) - ClearLoaded() -} - -func TestLoadFromMap(t *testing.T) { - assert.Equal(t, "", os.Getenv("DONT_ENV_TEST")) - - err := LoadFromMap(map[string]string{ - "DONT_ENV_TEST": "blog", - "dont_env_test1": "val1", - "dont_env_test2": "23", - }) - - assert.NoError(t, err) - - envStr := fmt.Sprint(os.Environ()) - assert.Contains(t, envStr, "DONT_ENV_TEST=blog") - assert.Contains(t, envStr, "DONT_ENV_TEST1=val1") - - assert.Equal(t, "blog", Get("DONT_ENV_TEST")) - assert.Equal(t, "blog", os.Getenv("DONT_ENV_TEST")) - assert.Equal(t, "val1", Get("DONT_ENV_TEST1")) - assert.Equal(t, 23, Int("DONT_ENV_TEST2")) - - // on windows, os.Getenv() not case sensitive - if runtime.GOOS == "windows" { - assert.Equal(t, "val1", Get("dont_env_test1")) - assert.Equal(t, 23, Int("dont_env_test2")) - } else { - assert.Equal(t, "val1", Get("dont_env_test1")) - assert.Equal(t, 23, Int("dont_env_test2")) - } - - assert.Equal(t, 20, Int("dont_env_test1", 20)) - assert.Equal(t, 20, Int("dont_env_not_exist", 20)) - - // check cache - assert.Contains(t, LoadedData(), "DONT_ENV_TEST2") - - // clear - ClearLoaded() - assert.Equal(t, "", os.Getenv("DONT_ENV_TEST")) - assert.Equal(t, "", Get("DONT_ENV_TEST1")) - - err = LoadFromMap(map[string]string{ - "": "val", - }) - assert.Error(t, err) -} diff --git a/dotnev/testdata/.env b/dotnev/testdata/.env deleted file mode 100644 index f09f7d3..0000000 --- a/dotnev/testdata/.env +++ /dev/null @@ -1,2 +0,0 @@ -# comments -DONT_ENV_TEST = "blog" \ No newline at end of file diff --git a/dotnev/testdata/error.ini b/dotnev/testdata/error.ini deleted file mode 100644 index f412958..0000000 --- a/dotnev/testdata/error.ini +++ /dev/null @@ -1,2 +0,0 @@ -DONT_ENV_TEST = -df \ No newline at end of file