From 0a4709d64811cd0e32fa13091028e23befd5ed12 Mon Sep 17 00:00:00 2001 From: Yishen Miao Date: Sun, 11 Jun 2023 11:25:44 -0700 Subject: [PATCH] Updating env Updates env to v8.0.0. --- cdh.go | 2 +- go.mod | 2 +- go.sum | 4 +- .../caarlos0/env/{v7 => v8}/.gitignore | 0 .../caarlos0/env/{v7 => v8}/.golangci.yml | 0 .../caarlos0/env/{v7 => v8}/.goreleaser.yml | 0 vendor/github.com/caarlos0/env/v8/.mailmap | 7 + .../caarlos0/env/{v7 => v8}/LICENSE.md | 0 .../caarlos0/env/{v7 => v8}/Makefile | 0 .../caarlos0/env/{v7 => v8}/README.md | 31 ++-- .../github.com/caarlos0/env/{v7 => v8}/env.go | 136 ++++++++---------- .../caarlos0/env/{v7 => v8}/env_unix.go | 0 .../caarlos0/env/{v7 => v8}/env_windows.go | 0 .../caarlos0/env/{v7 => v8}/error.go | 0 vendor/modules.txt | 4 +- 15 files changed, 85 insertions(+), 101 deletions(-) rename vendor/github.com/caarlos0/env/{v7 => v8}/.gitignore (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/.golangci.yml (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/.goreleaser.yml (100%) create mode 100644 vendor/github.com/caarlos0/env/v8/.mailmap rename vendor/github.com/caarlos0/env/{v7 => v8}/LICENSE.md (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/Makefile (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/README.md (95%) rename vendor/github.com/caarlos0/env/{v7 => v8}/env.go (78%) rename vendor/github.com/caarlos0/env/{v7 => v8}/env_unix.go (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/env_windows.go (100%) rename vendor/github.com/caarlos0/env/{v7 => v8}/error.go (100%) diff --git a/cdh.go b/cdh.go index 6e943227..412eee4a 100644 --- a/cdh.go +++ b/cdh.go @@ -28,7 +28,7 @@ import ( "path/filepath" "strings" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" "github.com/miekg/dns" gcdns "google.golang.org/api/dns/v1" "google.golang.org/api/option" diff --git a/go.mod b/go.mod index efab0773..f82e3e2d 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/mys721tx/cdh require ( - github.com/caarlos0/env/v7 v7.1.0 + github.com/caarlos0/env/v8 v8.0.0 github.com/miekg/dns v1.1.54 google.golang.org/api v0.126.0 ) diff --git a/go.sum b/go.sum index 07ae4b1b..dd2f98ee 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/caarlos0/env/v7 v7.1.0 h1:9lzTF5amyQeWHZzuZeKlCb5FWSUxpG1js43mhbY8ozg= -github.com/caarlos0/env/v7 v7.1.0/go.mod h1:LPPWniDUq4JaO6Q41vtlyikhMknqymCLBw0eX4dcH1E= +github.com/caarlos0/env/v8 v8.0.0 h1:POhxHhSpuxrLMIdvTGARuZqR4Jjm8AYmoi/JKlcScs0= +github.com/caarlos0/env/v8 v8.0.0/go.mod h1:7K4wMY9bH0esiXSSHlfHLX5xKGQMnkH5Fk4TDSSSzfo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/vendor/github.com/caarlos0/env/v7/.gitignore b/vendor/github.com/caarlos0/env/v8/.gitignore similarity index 100% rename from vendor/github.com/caarlos0/env/v7/.gitignore rename to vendor/github.com/caarlos0/env/v8/.gitignore diff --git a/vendor/github.com/caarlos0/env/v7/.golangci.yml b/vendor/github.com/caarlos0/env/v8/.golangci.yml similarity index 100% rename from vendor/github.com/caarlos0/env/v7/.golangci.yml rename to vendor/github.com/caarlos0/env/v8/.golangci.yml diff --git a/vendor/github.com/caarlos0/env/v7/.goreleaser.yml b/vendor/github.com/caarlos0/env/v8/.goreleaser.yml similarity index 100% rename from vendor/github.com/caarlos0/env/v7/.goreleaser.yml rename to vendor/github.com/caarlos0/env/v8/.goreleaser.yml diff --git a/vendor/github.com/caarlos0/env/v8/.mailmap b/vendor/github.com/caarlos0/env/v8/.mailmap new file mode 100644 index 00000000..eeeee601 --- /dev/null +++ b/vendor/github.com/caarlos0/env/v8/.mailmap @@ -0,0 +1,7 @@ +Carlos Alexandro Becker Carlos A Becker +Carlos Alexandro Becker Carlos A Becker +Carlos Alexandro Becker Carlos Alexandro Becker +Carlos Alexandro Becker Carlos Alexandro Becker +Carlos Alexandro Becker Carlos Becker +dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> +actions-user github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> diff --git a/vendor/github.com/caarlos0/env/v7/LICENSE.md b/vendor/github.com/caarlos0/env/v8/LICENSE.md similarity index 100% rename from vendor/github.com/caarlos0/env/v7/LICENSE.md rename to vendor/github.com/caarlos0/env/v8/LICENSE.md diff --git a/vendor/github.com/caarlos0/env/v7/Makefile b/vendor/github.com/caarlos0/env/v8/Makefile similarity index 100% rename from vendor/github.com/caarlos0/env/v7/Makefile rename to vendor/github.com/caarlos0/env/v8/Makefile diff --git a/vendor/github.com/caarlos0/env/v7/README.md b/vendor/github.com/caarlos0/env/v8/README.md similarity index 95% rename from vendor/github.com/caarlos0/env/v7/README.md rename to vendor/github.com/caarlos0/env/v8/README.md index 9d982cb5..171239a6 100644 --- a/vendor/github.com/caarlos0/env/v7/README.md +++ b/vendor/github.com/caarlos0/env/v8/README.md @@ -2,7 +2,7 @@ [![Build Status](https://img.shields.io/github/actions/workflow/status/caarlos0/env/build.yml?branch=main&style=for-the-badge)](https://github.com/caarlos0/env/actions?workflow=build) [![Coverage Status](https://img.shields.io/codecov/c/gh/caarlos0/env.svg?logo=codecov&style=for-the-badge)](https://codecov.io/gh/caarlos0/env) -[![](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge)](https://pkg.go.dev/github.com/caarlos0/env/v7) +[![](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge)](https://pkg.go.dev/github.com/caarlos0/env/v8) A simple and zero-dependencies library to parse environment variables into structs. @@ -11,7 +11,7 @@ A simple and zero-dependencies library to parse environment variables into struc Get the module with: ```sh -go get github.com/caarlos0/env/v7 +go get github.com/caarlos0/env/v8 ``` The usage looks like this: @@ -23,7 +23,7 @@ import ( "fmt" "time" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type config struct { @@ -110,15 +110,16 @@ of the variable. If you have a type that is not supported out of the box by the lib, you are able to use (or define) and pass custom parsers (and their associated `reflect.Type`) -to the `env.ParseWithFuncs()` function. +to the `env.ParseWithOptions()` function. In addition to accepting a struct pointer (same as `Parse()`), this function -also accepts a `map[reflect.Type]env.ParserFunc`. +also accepts a `Options{}`, and you can set your custom parsers in the `FuncMap` +field. If you add a custom parser for, say `Foo`, it will also be used to parse `*Foo` and `[]Foo` types. -Check the examples in the [go doc](http://pkg.go.dev/github.com/caarlos0/env/v7) +Check the examples in the [go doc](http://pkg.go.dev/github.com/caarlos0/env/v8) for more info. ### A note about `TextUnmarshaler` and `time.Time` @@ -196,7 +197,7 @@ package main import ( "fmt" "time" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type config struct { @@ -245,7 +246,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -283,7 +284,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -319,7 +320,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -353,7 +354,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -403,7 +404,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -442,7 +443,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -476,7 +477,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { @@ -509,7 +510,7 @@ import ( "fmt" "log" - "github.com/caarlos0/env/v7" + "github.com/caarlos0/env/v8" ) type Config struct { diff --git a/vendor/github.com/caarlos0/env/v7/env.go b/vendor/github.com/caarlos0/env/v8/env.go similarity index 78% rename from vendor/github.com/caarlos0/env/v7/env.go rename to vendor/github.com/caarlos0/env/v8/env.go index ce84c62f..5e6bcd07 100644 --- a/vendor/github.com/caarlos0/env/v7/env.go +++ b/vendor/github.com/caarlos0/env/v8/env.go @@ -117,72 +117,60 @@ type Options struct { // name by default if the `env` key is missing. UseFieldNameByDefault bool - // Sets to true if we have already configured once. - configured bool + // Custom parse functions for different types. + FuncMap map[reflect.Type]ParserFunc } -// configure will do the basic configurations and defaults. -func configure(opts []Options) []Options { - // If we have already configured the first item - // of options will have been configured set to true. - if len(opts) > 0 && opts[0].configured { - return opts - } - - // Created options with defaults. - opt := Options{ +func defaultOptions() Options { + return Options{ TagName: "env", Environment: toMap(os.Environ()), - configured: true, + FuncMap: defaultTypeParsers(), } - - // Loop over all opts structs and set - // to opt if value is not default/empty. - for _, item := range opts { - if item.Environment != nil { - opt.Environment = item.Environment - } - if item.TagName != "" { - opt.TagName = item.TagName - } - if item.OnSet != nil { - opt.OnSet = item.OnSet - } - if item.Prefix != "" { - opt.Prefix = item.Prefix - } - opt.UseFieldNameByDefault = item.UseFieldNameByDefault - opt.RequiredIfNoDef = item.RequiredIfNoDef - } - - return []Options{opt} } -func getOnSetFn(opts []Options) OnSetFn { - return opts[0].OnSet +func customOptions(opt Options) Options { + defOpts := defaultOptions() + if opt.TagName == "" { + opt.TagName = defOpts.TagName + } + if opt.Environment == nil { + opt.Environment = defOpts.Environment + } + if opt.FuncMap == nil { + opt.FuncMap = map[reflect.Type]ParserFunc{} + } + for k, v := range defOpts.FuncMap { + opt.FuncMap[k] = v + } + return opt } -// getTagName returns the tag name. -func getTagName(opts []Options) string { - return opts[0].TagName +func optionsWithEnvPrefix(field reflect.StructField, opts Options) Options { + return Options{ + Environment: opts.Environment, + TagName: opts.TagName, + RequiredIfNoDef: opts.RequiredIfNoDef, + OnSet: opts.OnSet, + Prefix: opts.Prefix + field.Tag.Get("envPrefix"), + UseFieldNameByDefault: opts.UseFieldNameByDefault, + FuncMap: opts.FuncMap, + } } -// getEnvironment returns the environment map. -func getEnvironment(opts []Options) map[string]string { - return opts[0].Environment +// Parse parses a struct containing `env` tags and loads its values from +// environment variables. +func Parse(v interface{}) error { + return parseInternal(v, defaultOptions()) } // Parse parses a struct containing `env` tags and loads its values from // environment variables. -func Parse(v interface{}, opts ...Options) error { - return ParseWithFuncs(v, map[reflect.Type]ParserFunc{}, opts...) +func ParseWithOptions(v interface{}, opts Options) error { + return parseInternal(v, customOptions(opts)) } -// ParseWithFuncs is the same as `Parse` except it also allows the user to pass -// in custom parsers. -func ParseWithFuncs(v interface{}, funcMap map[reflect.Type]ParserFunc, opts ...Options) error { - opts = configure(opts) - +func parseInternal(v interface{}, opts Options) error { ptrRef := reflect.ValueOf(v) if ptrRef.Kind() != reflect.Ptr { return newAggregateError(NotStructPtrError{}) @@ -191,15 +179,10 @@ func ParseWithFuncs(v interface{}, funcMap map[reflect.Type]ParserFunc, opts ... if ref.Kind() != reflect.Struct { return newAggregateError(NotStructPtrError{}) } - parsers := defaultTypeParsers() - for k, v := range funcMap { - parsers[k] = v - } - - return doParse(ref, parsers, opts) + return doParse(ref, opts) } -func doParse(ref reflect.Value, funcMap map[reflect.Type]ParserFunc, opts []Options) error { +func doParse(ref reflect.Value, opts Options) error { refType := ref.Type() var agrErr AggregateError @@ -208,7 +191,7 @@ func doParse(ref reflect.Value, funcMap map[reflect.Type]ParserFunc, opts []Opti refField := ref.Field(i) refTypeField := refType.Field(i) - if err := doParseField(refField, refTypeField, funcMap, opts); err != nil { + if err := doParseField(refField, refTypeField, opts); err != nil { if val, ok := err.(AggregateError); ok { agrErr.Errors = append(agrErr.Errors, val.Errors...) } else { @@ -224,15 +207,15 @@ func doParse(ref reflect.Value, funcMap map[reflect.Type]ParserFunc, opts []Opti return agrErr } -func doParseField(refField reflect.Value, refTypeField reflect.StructField, funcMap map[reflect.Type]ParserFunc, opts []Options) error { +func doParseField(refField reflect.Value, refTypeField reflect.StructField, opts Options) error { if !refField.CanSet() { return nil } if reflect.Ptr == refField.Kind() && !refField.IsNil() { - return ParseWithFuncs(refField.Interface(), funcMap, optsWithPrefix(refTypeField, opts)...) + return parseInternal(refField.Interface(), optionsWithEnvPrefix(refTypeField, opts)) } if reflect.Struct == refField.Kind() && refField.CanAddr() && refField.Type().Name() == "" { - return ParseWithFuncs(refField.Addr().Interface(), funcMap, optsWithPrefix(refTypeField, opts)...) + return parseInternal(refField.Addr().Interface(), optionsWithEnvPrefix(refTypeField, opts)) } value, err := get(refTypeField, opts) if err != nil { @@ -240,11 +223,11 @@ func doParseField(refField reflect.Value, refTypeField reflect.StructField, func } if value != "" { - return set(refField, refTypeField, value, funcMap) + return set(refField, refTypeField, value, opts.FuncMap) } if reflect.Struct == refField.Kind() { - return doParse(refField, funcMap, optsWithPrefix(refTypeField, opts)) + return doParse(refField, optionsWithEnvPrefix(refTypeField, opts)) } return nil @@ -263,20 +246,19 @@ func toEnvName(input string) string { return string(output) } -func get(field reflect.StructField, opts []Options) (val string, err error) { +func get(field reflect.StructField, opts Options) (val string, err error) { var exists bool var isDefault bool var loadFile bool var unset bool var notEmpty bool - required := opts[0].RequiredIfNoDef - prefix := opts[0].Prefix - ownKey, tags := parseKeyForOption(field.Tag.Get(getTagName(opts))) - if ownKey == "" && opts[0].UseFieldNameByDefault { + required := opts.RequiredIfNoDef + ownKey, tags := parseKeyForOption(field.Tag.Get(opts.TagName)) + if ownKey == "" && opts.UseFieldNameByDefault { ownKey = toEnvName(field.Name) } - key := prefix + ownKey + for _, tag := range tags { switch tag { case "": @@ -293,9 +275,12 @@ func get(field reflect.StructField, opts []Options) (val string, err error) { return "", newNoSupportedTagOptionError(tag) } } + + prefix := opts.Prefix + key := prefix + ownKey expand := strings.EqualFold(field.Tag.Get("envExpand"), "true") defaultValue, defExists := field.Tag.Lookup("envDefault") - val, exists, isDefault = getOr(key, defaultValue, defExists, getEnvironment(opts)) + val, exists, isDefault = getOr(key, defaultValue, defExists, opts.Environment) if expand { val = os.ExpandEnv(val) @@ -321,8 +306,8 @@ func get(field reflect.StructField, opts []Options) (val string, err error) { } } - if onSetFn := getOnSetFn(opts); onSetFn != nil { - onSetFn(key, val, isDefault) + if opts.OnSet != nil { + opts.OnSet(key, val, isDefault) } return val, err } @@ -529,12 +514,3 @@ func parseTextUnmarshalers(field reflect.Value, data []string, sf reflect.Struct return nil } - -func optsWithPrefix(field reflect.StructField, opts []Options) []Options { - subOpts := make([]Options, len(opts)) - copy(subOpts, opts) - if prefix := field.Tag.Get("envPrefix"); prefix != "" { - subOpts[0].Prefix += prefix - } - return subOpts -} diff --git a/vendor/github.com/caarlos0/env/v7/env_unix.go b/vendor/github.com/caarlos0/env/v8/env_unix.go similarity index 100% rename from vendor/github.com/caarlos0/env/v7/env_unix.go rename to vendor/github.com/caarlos0/env/v8/env_unix.go diff --git a/vendor/github.com/caarlos0/env/v7/env_windows.go b/vendor/github.com/caarlos0/env/v8/env_windows.go similarity index 100% rename from vendor/github.com/caarlos0/env/v7/env_windows.go rename to vendor/github.com/caarlos0/env/v8/env_windows.go diff --git a/vendor/github.com/caarlos0/env/v7/error.go b/vendor/github.com/caarlos0/env/v8/error.go similarity index 100% rename from vendor/github.com/caarlos0/env/v7/error.go rename to vendor/github.com/caarlos0/env/v8/error.go diff --git a/vendor/modules.txt b/vendor/modules.txt index 5c4e2eea..7fd6e667 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,9 +4,9 @@ cloud.google.com/go/compute/internal # cloud.google.com/go/compute/metadata v0.2.3 ## explicit; go 1.19 cloud.google.com/go/compute/metadata -# github.com/caarlos0/env/v7 v7.1.0 +# github.com/caarlos0/env/v8 v8.0.0 ## explicit; go 1.17 -github.com/caarlos0/env/v7 +github.com/caarlos0/env/v8 # github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da ## explicit github.com/golang/groupcache/lru