From 47015e78b1ae22db8a209177ad4482a0c0a69f7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 5 Apr 2023 22:09:15 +0400 Subject: [PATCH] chore(deps): bump github.com/obalunenko/getenv from 1.9.1 to 1.10.0 (#258) Bumps [github.com/obalunenko/getenv](https://github.com/obalunenko/getenv) from 1.9.1 to 1.10.0. - [Release notes](https://github.com/obalunenko/getenv/releases) - [Changelog](https://github.com/obalunenko/getenv/blob/master/.goreleaser.yml) - [Commits](https://github.com/obalunenko/getenv/compare/v1.9.1...v1.10.0) --- updated-dependencies: - dependency-name: github.com/obalunenko/getenv dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/obalunenko/getenv/Makefile | 24 +-- vendor/github.com/obalunenko/getenv/README.md | 150 +++++++++++++++++- vendor/github.com/obalunenko/getenv/getenv.go | 35 ++++ vendor/modules.txt | 2 +- 6 files changed, 190 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 75d64140..f72e6763 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/briandowns/spinner v1.23.0 github.com/manifoldco/promptui v0.9.0 - github.com/obalunenko/getenv v1.9.1 + github.com/obalunenko/getenv v1.10.0 github.com/obalunenko/logger v0.6.0 github.com/obalunenko/version v1.1.0 github.com/savioxavier/termlink v1.2.1 diff --git a/go.sum b/go.sum index c09ee0fb..dc68f6e4 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/obalunenko/getenv v1.9.1 h1:cOtpDHd4V2fiTEoqIqp0DNr+TTKHNIXixNc+Sg6GX8U= -github.com/obalunenko/getenv v1.9.1/go.mod h1:aWb6RzOdu+NT7sBd0VcmYtu2YQ3TO34C5+ExFXIaLqw= +github.com/obalunenko/getenv v1.10.0 h1:hal7n2T/1YmlHohX/GU9NVhzYp9hqdbfxEP+CrBygeA= +github.com/obalunenko/getenv v1.10.0/go.mod h1:aWb6RzOdu+NT7sBd0VcmYtu2YQ3TO34C5+ExFXIaLqw= github.com/obalunenko/logger v0.6.0 h1:Sif4MYn6aGUA5pBTcKkMtJXTZNRZ52EiP4KLiFgMEkI= github.com/obalunenko/logger v0.6.0/go.mod h1:AOThqVHT+qlG5yMVarmVYPP37yytKxL89HfY8S56a1s= github.com/obalunenko/version v1.1.0 h1:yVua7OHnK3+MJpendeMmAlfzVmq7R1h8MO3Ufz7HEec= diff --git a/vendor/github.com/obalunenko/getenv/Makefile b/vendor/github.com/obalunenko/getenv/Makefile index f9fa780b..2d286258 100644 --- a/vendor/github.com/obalunenko/getenv/Makefile +++ b/vendor/github.com/obalunenko/getenv/Makefile @@ -1,3 +1,4 @@ +.PHONY: help, test-cover, prepare-cover-report, open-cover-report, update-readme-cover, update-readme-doc, test, test-regression, configure, sync-vendor, imports, fmt, format-project, install-tools, vet, lint-full, lint-pipeline, lint-sonar, release, release-local-snapshot, check-releaser, new-version BIN_DIR=./bin SHELL := env VERSION=$(VERSION) $(SHELL) @@ -6,7 +7,7 @@ VERSION ?= $(shell git describe --tags $(git rev-list --tags --max-count=1)) APP_NAME?=getenv SHELL := env APP_NAME=$(APP_NAME) $(SHELL) -GOTOOLS_IMAGE_TAG?=v0.5.0 +GOTOOLS_IMAGE_TAG?=v0.6.1 SHELL := env GOTOOLS_IMAGE_TAG=$(GOTOOLS_IMAGE_TAG) $(SHELL) COMPOSE_TOOLS_FILE=deployments/docker-compose/go-tools-docker-compose.yml @@ -38,35 +39,28 @@ help: ## Test coverage report. test-cover: ./scripts/tests/coverage.sh -.PHONY: test-cover prepare-cover-report: test-cover $(COMPOSE_TOOLS_CMD_UP) prepare-cover-report prepare-cover-report -.PHONY: prepare-cover-report ## Open coverage report. open-cover-report: prepare-cover-report ./scripts/open-coverage-report.sh -.PHONY: open-cover-report ## Update readme coverage. update-readme-cover: prepare-cover-report $(COMPOSE_TOOLS_CMD_UP) update-readme-coverage update-readme-coverage -.PHONY: update-readme-cover ## Update readme doc. update-readme-doc: $(COMPOSE_TOOLS_CMD_UP) update-readme-doc update-readme-doc -.PHONY: update-readme-doc ## Run tests. test: $(COMPOSE_TOOLS_CMD_UP) run-tests run-tests -.PHONY: test ## Run regression tests. test-regression: test -.PHONY: test-regression ## Sync vendor and install needed tools. configure: sync-vendor install-tools @@ -74,67 +68,55 @@ configure: sync-vendor install-tools ## Sync vendor with go.mod. sync-vendor: ./scripts/sync-vendor.sh -.PHONY: sync-vendor ## Fix imports sorting. imports: $(COMPOSE_TOOLS_CMD_UP) fix-imports fix-imports -.PHONY: imports ## Format code with go fmt. fmt: $(COMPOSE_TOOLS_CMD_UP) fix-fmt fix-fmt -.PHONY: fmt ## Format code and sort imports. format-project: fmt imports -.PHONY: format-project ## Installs vendored tools. install-tools: echo "Installing ${GOTOOLS_IMAGE_TAG}" $(COMPOSE_TOOLS_CMD_PULL) -.PHONY: install-tools ## vet project vet: ./scripts/linting/run-vet.sh -.PHONY: vet ## Run full linting lint-full: $(COMPOSE_TOOLS_CMD_UP) lint-full lint-full -.PHONY: lint-full ## Run linting for build pipeline lint-pipeline: $(COMPOSE_TOOLS_CMD_UP) lint-pipeline lint-pipeline -.PHONY: lint-pipeline ## Run linting for sonar report lint-sonar: $(COMPOSE_TOOLS_CMD_UP) lint-sonar lint-sonar -.PHONY: lint-sonar ## Release release: ./scripts/release/release.sh -.PHONY: release ## Release local snapshot release-local-snapshot: ./scripts/release/local-snapshot-release.sh -.PHONY: release-local-snapshot ## Check goreleaser config. check-releaser: ./scripts/release/check.sh -.PHONY: check-releaser ## Issue new release. new-version: vet test-regression ./scripts/release/new-version.sh -.PHONY: new-release + .DEFAULT_GOAL := help diff --git a/vendor/github.com/obalunenko/getenv/README.md b/vendor/github.com/obalunenko/getenv/README.md index aeda8046..c71d9fb8 100644 --- a/vendor/github.com/obalunenko/getenv/README.md +++ b/vendor/github.com/obalunenko/getenv/README.md @@ -56,6 +56,150 @@ Types supported: ## Examples +### Env + +Env retrieves the value of the environment variable named by the key. +If the variable is present in the environment the value will be parsed and returned. +Otherwise, an error will be returned. + +```golang +package main + +import ( + "fmt" + "net" + "net/url" + "os" + "time" + + "github.com/obalunenko/getenv" + "github.com/obalunenko/getenv/option" +) + +func main() { + const ( + key = "GH_GETENV_TEST" + ) + + var ( + val any + err error + ) + + defer func() { + if err = os.Unsetenv(key); err != nil { + panic(err) + } + }() + + // string + if err = os.Setenv(key, "golly"); err != nil { + panic(err) + } + + val, err = getenv.Env[string](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // int + if err = os.Setenv(key, "123"); err != nil { + panic(err) + } + + val, err = getenv.Env[int](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // int conversion error + if err = os.Setenv(key, "123s4"); err != nil { + panic(err) + } + + val, err = getenv.Env[int](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // time.Time + if err = os.Setenv(key, "2022-01-20"); err != nil { + panic(err) + } + + val, err = getenv.Env[time.Time](key, option.WithTimeLayout("2006-01-02")) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // []float64 + if err = os.Setenv(key, "26.89,0.67"); err != nil { + panic(err) + } + + val, err = getenv.Env[[]float64](key, option.WithSeparator(",")) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // time.Duration + if err = os.Setenv(key, "2h35m"); err != nil { + panic(err) + } + + val, err = getenv.Env[time.Duration](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // url.URL + if err = os.Setenv(key, "https://test:abcd123@golangbyexample.com:8000/tutorials/intro?type=advance&compact=false#history"); err != nil { + panic(err) + } + + val, err = getenv.Env[url.URL](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // net.IP + if err = os.Setenv(key, "2001:cb8::17"); err != nil { + panic(err) + } + + val, err = getenv.Env[net.IP](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // []string + if err = os.Setenv(key, "a,b,c,d"); err != nil { + panic(err) + } + + val, err = getenv.Env[[]string](key, option.WithSeparator(",")) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // complex128 + if err = os.Setenv(key, "1+2i"); err != nil { + panic(err) + } + + val, err = getenv.Env[complex128](key) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + + // []complex64 + if err = os.Setenv(key, "1+2i,3+4i"); err != nil { + panic(err) + } + + val, err = getenv.Env[[]complex64](key, option.WithSeparator(",")) + fmt.Printf("[%T]: %v; err: %v\n", val, val, err) + +} + +``` + +Output: + +``` +[string]: golly; err: +[int]: 123; err: +[int]: 0; err: could not parse variable[GH_GETENV_TEST] value[123s4] to type[int]: invalid value +[time.Time]: 2022-01-20 00:00:00 +0000 UTC; err: +[[]float64]: [26.89 0.67]; err: +[time.Duration]: 2h35m0s; err: +[url.URL]: {https test:abcd123 golangbyexample.com:8000 /tutorials/intro false false type=advance&compact=false history }; err: +[net.IP]: 2001:cb8::17; err: +[[]string]: [a b c d]; err: +[complex128]: (1+2i); err: +[[]complex64]: [(1+2i) (3+4i)]; err: +``` + ### EnvOrDefault EnvOrDefault retrieves the value of the environment variable named by the key. @@ -78,10 +222,12 @@ import ( ) func main() { - key := "GH_GETENV_TEST" + const ( + key = "GH_GETENV_TEST" + ) defer func() { - if err := os.Unsetenv("GH_GETENV_TEST"); err != nil { + if err := os.Unsetenv(key); err != nil { panic(err) } }() diff --git a/vendor/github.com/obalunenko/getenv/getenv.go b/vendor/github.com/obalunenko/getenv/getenv.go index f4934aa3..c8d36119 100644 --- a/vendor/github.com/obalunenko/getenv/getenv.go +++ b/vendor/github.com/obalunenko/getenv/getenv.go @@ -47,10 +47,45 @@ package getenv import ( + "errors" + "fmt" + "os" + "reflect" + "github.com/obalunenko/getenv/internal" "github.com/obalunenko/getenv/option" ) +var ( + // ErrNotSet is an error that is returned when the environment variable is not set. + ErrNotSet = errors.New("not set") + // ErrInvalidValue is an error that is returned when the environment variable is not valid. + ErrInvalidValue = errors.New("invalid value") +) + +// Env retrieves the value of the environment variable named by the key. +// If the variable is present in the environment the value will be parsed and returned. +// Otherwise, an error will be returned. +func Env[T internal.EnvParsable](key string, options ...option.Option) (T, error) { + // Create a default value of the same type as the value that we want to get. + var defVal T + + val := EnvOrDefault(key, defVal, options...) + + // If the value is equal to the default value, it means that the value was not parsed. + // This means that the environment variable was not set, or it was set to an invalid value. + if reflect.DeepEqual(val, defVal) { + v, ok := os.LookupEnv(key) + if !ok { + return val, fmt.Errorf("could not get variable[%s]: %w", key, ErrNotSet) + } + + return val, fmt.Errorf("could not parse variable[%s] value[%v] to type[%T]: %w", key, v, defVal, ErrInvalidValue) + } + + return val, nil +} + // EnvOrDefault retrieves the value of the environment variable named by the key. // If the variable is present in the environment the value will be parsed and returned. // Otherwise, the default value will be returned. diff --git a/vendor/modules.txt b/vendor/modules.txt index 91965015..98b76d7f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -37,7 +37,7 @@ github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.14 ## explicit; go 1.12 github.com/mattn/go-isatty -# github.com/obalunenko/getenv v1.9.1 +# github.com/obalunenko/getenv v1.10.0 ## explicit; go 1.20 github.com/obalunenko/getenv github.com/obalunenko/getenv/internal