From e8312299f886cbcddd655effa3af4f83fb0e307a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Mar 2023 11:57:28 +0000 Subject: [PATCH] chore(deps): bump github.com/obalunenko/getenv from 1.7.0 to 1.8.0 Bumps [github.com/obalunenko/getenv](https://github.com/obalunenko/getenv) from 1.7.0 to 1.8.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.7.0...v1.8.0) --- updated-dependencies: - dependency-name: github.com/obalunenko/getenv dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/obalunenko/getenv/README.md | 30 ++- vendor/github.com/obalunenko/getenv/getenv.go | 7 + .../obalunenko/getenv/internal/constraint.go | 9 +- .../obalunenko/getenv/internal/iface.go | 108 ++++++++++- .../obalunenko/getenv/internal/parsers.go | 172 +++++++++++++++++- vendor/modules.txt | 2 +- 8 files changed, 316 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 5645a49c..6976a7b9 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.7.0 + github.com/obalunenko/getenv v1.8.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 c48659cb..40c2f971 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.7.0 h1:ubA0CF4phtTPpE5IVH0ePCTzPfztcHtM09oqYsPBflI= -github.com/obalunenko/getenv v1.7.0/go.mod h1:aWb6RzOdu+NT7sBd0VcmYtu2YQ3TO34C5+ExFXIaLqw= +github.com/obalunenko/getenv v1.8.0 h1:YReGdbhEnQg9vBjh4fKxEzHLJwG0EUilszshxRKfVKM= +github.com/obalunenko/getenv v1.8.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/README.md b/vendor/github.com/obalunenko/getenv/README.md index 91ff6050..95f950f5 100644 --- a/vendor/github.com/obalunenko/getenv/README.md +++ b/vendor/github.com/obalunenko/getenv/README.md @@ -2,8 +2,9 @@ [![Go Reference](https://pkg.go.dev/badge/github.com/obalunenko/getenv.svg)](https://pkg.go.dev/github.com/obalunenko/getenv) [![Go Report Card](https://goreportcard.com/badge/github.com/obalunenko/getenv)](https://goreportcard.com/report/github.com/obalunenko/getenv) [![codecov](https://codecov.io/gh/obalunenko/getenv/branch/master/graph/badge.svg)](https://codecov.io/gh/obalunenko/getenv) -![coverbadger-tag-do-not-edit](https://img.shields.io/badge/coverage-97.56%25-brightgreen?longCache=true&style=flat) +![coverbadger-tag-do-not-edit](https://img.shields.io/badge/coverage-98.93%25-brightgreen?longCache=true&style=flat) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=obalunenko_getenv&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=obalunenko_getenv) + # getenv Package getenv provides functionality for loading environment variables and parse them into go builtin types. @@ -22,7 +23,9 @@ Types supported: - int64 - []int64 - uint8 +- []uint8 - uint16 +- []uint16 - uint64 - []uint64 - uint @@ -30,13 +33,18 @@ Types supported: - uint32 - []uint32 - float32 +- []float32 - float64 - []float64 - time.Time - []time.Time - time.Duration +- []time.Duration - bool - url.URL +- []url.URL +- net.IP +- []net.IP ## Examples @@ -51,6 +59,8 @@ package main import ( "fmt" + "net" + "net/url" "os" "time" @@ -114,6 +124,22 @@ func main() { val = getenv.EnvOrDefault(key, time.Second) fmt.Printf("[%T]: %v\n", val, val) + // 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 = getenv.EnvOrDefault(key, url.URL{}) + fmt.Printf("[%T]: %v\n", val, val) + + // net.IP + if err := os.Setenv(key, "2001:cb8::17"); err != nil { + panic(err) + } + + val = getenv.EnvOrDefault(key, net.IP{}) + fmt.Printf("[%T]: %v\n", val, val) + } ``` @@ -126,4 +152,6 @@ Output: [time.Time]: 2022-01-20 00:00:00 +0000 UTC [[]float64]: [26.89 0.67] [time.Duration]: 2h35m0s +[url.URL]: {https test:abcd123 golangbyexample.com:8000 /tutorials/intro false false type=advance&compact=false history } +[net.IP]: 2001:cb8::17 ``` diff --git a/vendor/github.com/obalunenko/getenv/getenv.go b/vendor/github.com/obalunenko/getenv/getenv.go index d6072760..3ba4aeec 100644 --- a/vendor/github.com/obalunenko/getenv/getenv.go +++ b/vendor/github.com/obalunenko/getenv/getenv.go @@ -14,7 +14,9 @@ // - int64 // - []int64 // - uint8 +// - []uint8 // - uint16 +// - []uint16 // - uint64 // - []uint64 // - uint @@ -22,13 +24,18 @@ // - uint32 // - []uint32 // - float32 +// - []float32 // - float64 // - []float64 // - time.Time // - []time.Time // - time.Duration +// - []time.Duration // - bool // - url.URL +// - []url.URL +// - net.IP +// - []net.IP package getenv import ( diff --git a/vendor/github.com/obalunenko/getenv/internal/constraint.go b/vendor/github.com/obalunenko/getenv/internal/constraint.go index dd72d411..8bf4293a 100644 --- a/vendor/github.com/obalunenko/getenv/internal/constraint.go +++ b/vendor/github.com/obalunenko/getenv/internal/constraint.go @@ -1,6 +1,7 @@ package internal import ( + "net" "net/url" "time" ) @@ -8,7 +9,7 @@ import ( type ( // EnvParsable is a constraint for supported environment variable types parsers. EnvParsable interface { - String | Int | Uint | Float | Time | bool | url.URL + String | Int | Uint | Float | Time | bool | url.URL | []url.URL | net.IP | []net.IP } // String is a constraint for strings and slice of strings. @@ -23,16 +24,16 @@ type ( // Uint is a constraint for unsigned integer and slice of unsigned integers. Uint interface { - uint | []uint | uint8 | uint16 | uint32 | []uint32 | uint64 | []uint64 + uint | []uint | uint8 | []uint8 | uint16 | []uint16 | uint32 | []uint32 | uint64 | []uint64 } // Float is a constraint for floats and slice of floats. Float interface { - float32 | float64 | []float64 + float32 | []float32 | float64 | []float64 } // Time is a constraint for time.Time and time.Duration. Time interface { - time.Time | []time.Time | time.Duration + time.Time | []time.Time | time.Duration | []time.Duration } ) diff --git a/vendor/github.com/obalunenko/getenv/internal/iface.go b/vendor/github.com/obalunenko/getenv/internal/iface.go index 8b873615..4b74e35d 100644 --- a/vendor/github.com/obalunenko/getenv/internal/iface.go +++ b/vendor/github.com/obalunenko/getenv/internal/iface.go @@ -3,6 +3,7 @@ package internal import ( "fmt" + "net" "net/url" "time" ) @@ -16,20 +17,22 @@ func NewEnvParser(v any) EnvParser { p = newStringParser(t) case int, []int, int8, []int8, int16, []int16, int32, []int32, int64, []int64: p = newIntParser(t) - case uint, []uint, uint8, uint16, uint32, []uint32, uint64, []uint64: + case uint, []uint, uint8, []uint8, uint16, []uint16, uint32, []uint32, uint64, []uint64: p = newUintParser(t) case bool: p = boolParser(t) - case float32, float64, []float64: + case float32, []float32, float64, []float64: p = newFloatParser(t) - case time.Time: - p = timeParser(t) - case []time.Time: - p = timeSliceParser(t) - case time.Duration: - p = durationParser(t) + case time.Time, []time.Time, time.Duration, []time.Duration: + p = newTimeParser(t) case url.URL: p = urlParser(t) + case []url.URL: + p = urlSliceParser(t) + case net.IP: + p = ipParser(t) + case []net.IP: + p = ipSliceParser(t) default: p = nil } @@ -83,12 +86,16 @@ func newUintParser(v any) EnvParser { switch t := v.(type) { case uint8: return uint8Parser(t) + case []uint8: + return uint8SliceParser(t) case uint: return uintParser(t) case []uint: return uintSliceParser(t) case uint16: return uint16Parser(t) + case []uint16: + return uint16SliceParser(t) case uint32: return uint32Parser(t) case []uint32: @@ -106,6 +113,8 @@ func newFloatParser(v any) EnvParser { switch t := v.(type) { case float32: return float32Parser(t) + case []float32: + return float32SliceParser(t) case float64: return float64Parser(t) case []float64: @@ -115,6 +124,21 @@ func newFloatParser(v any) EnvParser { } } +func newTimeParser(v any) EnvParser { + switch t := v.(type) { + case time.Time: + return timeParser(t) + case []time.Time: + return timeSliceParser(t) + case time.Duration: + return durationParser(t) + case []time.Duration: + return durationSliceParser(t) + default: + return nil + } +} + // EnvParser interface for parsing environment variables. type EnvParser interface { ParseEnv(key string, defaltVal any, options Parameters) any @@ -156,6 +180,16 @@ func (i intSliceParser) ParseEnv(key string, defaltVal any, options Parameters) return val } +type float32SliceParser []float32 + +func (i float32SliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { + sep := options.Separator + + val := float32SliceOrDefault(key, defaltVal.([]float32), sep) + + return val +} + type float64SliceParser []float64 func (i float64SliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { @@ -283,6 +317,16 @@ func (t timeSliceParser) ParseEnv(key string, defaltVal any, options Parameters) return val } +type durationSliceParser []time.Duration + +func (t durationSliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { + sep := options.Separator + + val := durationSliceOrDefault(key, defaltVal.([]time.Duration), sep) + + return val +} + type durationParser time.Duration func (d durationParser) ParseEnv(key string, defaltVal any, _ Parameters) any { @@ -335,6 +379,16 @@ func (i uintSliceParser) ParseEnv(key string, defaltVal any, options Parameters) return val } +type uint8SliceParser []uint8 + +func (i uint8SliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { + sep := options.Separator + + val := uint8SliceOrDefault(key, defaltVal.([]uint8), sep) + + return val +} + type uint32SliceParser []uint32 func (i uint32SliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { @@ -345,6 +399,16 @@ func (i uint32SliceParser) ParseEnv(key string, defaltVal any, options Parameter return val } +type uint16SliceParser []uint16 + +func (i uint16SliceParser) ParseEnv(key string, defaltVal any, options Parameters) any { + sep := options.Separator + + val := uint16SliceOrDefault(key, defaltVal.([]uint16), sep) + + return val +} + type uint16Parser uint func (d uint16Parser) ParseEnv(key string, defaltVal any, _ Parameters) any { @@ -368,3 +432,31 @@ func (t urlParser) ParseEnv(key string, defaltVal any, _ Parameters) any { return val } + +type urlSliceParser []url.URL + +func (t urlSliceParser) ParseEnv(key string, defaltVal any, opts Parameters) any { + separator := opts.Separator + + val := urlSliceOrDefault(key, defaltVal.([]url.URL), separator) + + return val +} + +type ipParser net.IP + +func (t ipParser) ParseEnv(key string, defaltVal any, _ Parameters) any { + val := ipOrDefault(key, defaltVal.(net.IP)) + + return val +} + +type ipSliceParser []net.IP + +func (t ipSliceParser) ParseEnv(key string, defaltVal any, opts Parameters) any { + separator := opts.Separator + + val := ipSliceOrDefault(key, defaltVal.([]net.IP), separator) + + return val +} diff --git a/vendor/github.com/obalunenko/getenv/internal/parsers.go b/vendor/github.com/obalunenko/getenv/internal/parsers.go index ea3ab227..ad9a9feb 100644 --- a/vendor/github.com/obalunenko/getenv/internal/parsers.go +++ b/vendor/github.com/obalunenko/getenv/internal/parsers.go @@ -1,6 +1,7 @@ package internal import ( + "net" "net/url" "os" "strconv" @@ -95,7 +96,34 @@ func intSliceOrDefault(key string, defaultVal []int, sep string) []int { return val } -// intSliceOrDefault retrieves the int slice value of the environment variable named +// float32SliceOrDefault retrieves the float32 slice value of the environment variable named +// by the key and separated by sep. +// If variable not set or value is empty - defaultVal will be returned. +func float32SliceOrDefault(key string, defaultVal []float32, sep string) []float32 { + valraw := stringSliceOrDefault(key, nil, sep) + if valraw == nil { + return defaultVal + } + + val := make([]float32, 0, len(valraw)) + + const ( + bitsize = 32 + ) + + for _, s := range valraw { + v, err := strconv.ParseFloat(s, bitsize) + if err != nil { + return defaultVal + } + + val = append(val, float32(v)) + } + + return val +} + +// float64SliceOrDefault retrieves the float64 slice value of the environment variable named // by the key and separated by sep. // If variable not set or value is empty - defaultVal will be returned. func float64SliceOrDefault(key string, defaultVal []float64, sep string) []float64 { @@ -291,6 +319,29 @@ func timeSliceOrDefault(key string, defaultVal []time.Time, layout, separator st return val } +// durationSliceOrDefault retrieves the []time.Duration value of the environment variable named +// by the key represented by layout. +// If variable not set or value is empty - defaultVal will be returned. +func durationSliceOrDefault(key string, defaultVal []time.Duration, separator string) []time.Duration { + valraw := stringSliceOrDefault(key, nil, separator) + if valraw == nil { + return defaultVal + } + + val := make([]time.Duration, 0, len(valraw)) + + for _, s := range valraw { + v, err := time.ParseDuration(s) + if err != nil { + return defaultVal + } + + val = append(val, v) + } + + return val +} + // int64OrDefault retrieves the int64 value of the environment variable named // by the key. // If variable not set or value is empty - defaultVal will be returned. @@ -543,6 +594,62 @@ func uintSliceOrDefault(key string, defaultVal []uint, sep string) []uint { return val } +// uint8SliceOrDefault retrieves the uint8 slice value of the environment variable named +// by the key and separated by sep. +// If variable not set or value is empty - defaultVal will be returned. +func uint8SliceOrDefault(key string, defaultVal []uint8, sep string) []uint8 { + valraw := stringSliceOrDefault(key, nil, sep) + if valraw == nil { + return defaultVal + } + + val := make([]uint8, 0, len(valraw)) + + const ( + base = 10 + bitsize = 8 + ) + + for _, s := range valraw { + v, err := strconv.ParseUint(s, base, bitsize) + if err != nil { + return defaultVal + } + + val = append(val, uint8(v)) + } + + return val +} + +// uint16SliceOrDefault retrieves the uint16 slice value of the environment variable named +// by the key and separated by sep. +// If variable not set or value is empty - defaultVal will be returned. +func uint16SliceOrDefault(key string, defaultVal []uint16, sep string) []uint16 { + valraw := stringSliceOrDefault(key, nil, sep) + if valraw == nil { + return defaultVal + } + + val := make([]uint16, 0, len(valraw)) + + const ( + base = 10 + bitsize = 16 + ) + + for _, s := range valraw { + v, err := strconv.ParseUint(s, base, bitsize) + if err != nil { + return defaultVal + } + + val = append(val, uint16(v)) + } + + return val +} + // uint32SliceOrDefault retrieves the uint32 slice value of the environment variable named // by the key and separated by sep. // If variable not set or value is empty - defaultVal will be returned. @@ -631,3 +738,66 @@ func urlOrDefault(key string, defaultVal url.URL) url.URL { return *val } + +// urlSliceOrDefault retrieves the url.URL slice value of the environment variable named +// by the key and separated by sep. +// If variable not set or value is empty - defaultVal will be returned. +func urlSliceOrDefault(key string, defaultVal []url.URL, sep string) []url.URL { + valraw := stringSliceOrDefault(key, nil, sep) + if valraw == nil { + return defaultVal + } + + val := make([]url.URL, 0, len(valraw)) + + for _, s := range valraw { + v, err := url.Parse(s) + if err != nil { + return defaultVal + } + + val = append(val, *v) + } + + return val +} + +// ipOrDefault retrieves the net.IP value of the environment variable named +// by the key represented by layout. +// If variable not set or value is empty - defaultVal will be returned. +func ipOrDefault(key string, defaultVal net.IP) net.IP { + env := stringOrDefault(key, "") + if env == "" { + return defaultVal + } + + val := net.ParseIP(env) + if val == nil { + return defaultVal + } + + return val +} + +// ipSliceOrDefault retrieves the net.IP slice value of the environment variable named +// by the key and separated by sep. +// If variable not set or value is empty - defaultVal will be returned. +func ipSliceOrDefault(key string, defaultVal []net.IP, sep string) []net.IP { + valraw := stringSliceOrDefault(key, nil, sep) + if valraw == nil { + return defaultVal + } + + val := make([]net.IP, 0, len(valraw)) + + for _, s := range valraw { + v := net.ParseIP(s) + if v == nil { + return defaultVal + } + + val = append(val, v) + } + + return val +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7cccd2c6..a58611d3 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.7.0 +# github.com/obalunenko/getenv v1.8.0 ## explicit; go 1.20 github.com/obalunenko/getenv github.com/obalunenko/getenv/internal