@@ -9,14 +9,6 @@ import (
99 "strconv"
1010)
1111
12- var (
13- errEnvironmentValueRequired = errors .New ("require either value or env" )
14- // ErrEnvironmentVariableRequired the error happens when the name of environment variable is empty.
15- ErrEnvironmentVariableRequired = errors .New ("the environment variable name is empty" )
16- // ErrEnvironmentVariableValueRequired the error happens when the value from environment variable is empty.
17- ErrEnvironmentVariableValueRequired = errors .New ("the environment variable value is empty" )
18- )
19-
2012// EnvString represents either a literal string or an environment reference.
2113type EnvString struct {
2214 Value * string `json:"value,omitempty" jsonschema:"anyof_required=value" mapstructure:"value" yaml:"value,omitempty"`
@@ -66,6 +58,12 @@ func (ev *EnvString) UnmarshalJSON(b []byte) error {
6658 return nil
6759}
6860
61+ // IsZero checks if the instance is empty.
62+ func (ev EnvString ) IsZero () bool {
63+ return (ev .Variable == nil || * ev .Variable == "" ) &&
64+ ev .Value == nil
65+ }
66+
6967// Get gets literal value or from system environment.
7068func (ev EnvString ) Get () (string , error ) {
7169 err := validateEnvironmentValue (ev .Value , ev .Variable )
@@ -138,6 +136,12 @@ func NewEnvIntVariable(name string) EnvInt {
138136 }
139137}
140138
139+ // IsZero checks if the instance is empty.
140+ func (ev EnvInt ) IsZero () bool {
141+ return (ev .Variable == nil || * ev .Variable == "" ) &&
142+ ev .Value == nil
143+ }
144+
141145// UnmarshalJSON implements json.Unmarshaler.
142146func (ev * EnvInt ) UnmarshalJSON (b []byte ) error {
143147 type Plain EnvInt
@@ -222,6 +226,12 @@ func NewEnvBoolVariable(name string) EnvBool {
222226 }
223227}
224228
229+ // IsZero checks if the instance is empty.
230+ func (ev EnvBool ) IsZero () bool {
231+ return (ev .Variable == nil || * ev .Variable == "" ) &&
232+ ev .Value == nil
233+ }
234+
225235// UnmarshalJSON implements json.Unmarshaler.
226236func (ev * EnvBool ) UnmarshalJSON (b []byte ) error {
227237 type Plain EnvBool
@@ -306,6 +316,12 @@ func NewEnvFloatVariable(name string) EnvFloat {
306316 }
307317}
308318
319+ // IsZero checks if the instance is empty.
320+ func (ev EnvFloat ) IsZero () bool {
321+ return (ev .Variable == nil || * ev .Variable == "" ) &&
322+ ev .Value == nil
323+ }
324+
309325// UnmarshalJSON implements json.Unmarshaler.
310326func (ev * EnvFloat ) UnmarshalJSON (b []byte ) error {
311327 type Plain EnvFloat
@@ -390,6 +406,12 @@ func NewEnvMapStringVariable(name string) EnvMapString {
390406 }
391407}
392408
409+ // IsZero checks if the instance is empty.
410+ func (ev EnvMapString ) IsZero () bool {
411+ return (ev .Variable == nil || * ev .Variable == "" ) &&
412+ ev .Value == nil
413+ }
414+
393415// UnmarshalJSON implements json.Unmarshaler.
394416func (ev * EnvMapString ) UnmarshalJSON (b []byte ) error {
395417 type Plain EnvMapString
@@ -456,6 +478,12 @@ func NewEnvMapIntVariable(name string) EnvMapInt {
456478 }
457479}
458480
481+ // IsZero checks if the instance is empty.
482+ func (ev EnvMapInt ) IsZero () bool {
483+ return (ev .Variable == nil || * ev .Variable == "" ) &&
484+ ev .Value == nil
485+ }
486+
459487// UnmarshalJSON implements json.Unmarshaler.
460488func (ev * EnvMapInt ) UnmarshalJSON (b []byte ) error {
461489 type Plain EnvMapInt
@@ -522,6 +550,12 @@ func NewEnvMapFloatVariable(name string) EnvMapFloat {
522550 }
523551}
524552
553+ // IsZero checks if the instance is empty.
554+ func (ev EnvMapFloat ) IsZero () bool {
555+ return (ev .Variable == nil || * ev .Variable == "" ) &&
556+ ev .Value == nil
557+ }
558+
525559// UnmarshalJSON implements json.Unmarshaler.
526560func (ev * EnvMapFloat ) UnmarshalJSON (b []byte ) error {
527561 type Plain EnvMapFloat
@@ -588,6 +622,12 @@ func NewEnvMapBoolVariable(name string) EnvMapBool {
588622 }
589623}
590624
625+ // IsZero checks if the instance is empty.
626+ func (ev EnvMapBool ) IsZero () bool {
627+ return (ev .Variable == nil || * ev .Variable == "" ) &&
628+ ev .Value == nil
629+ }
630+
591631// UnmarshalJSON implements json.Unmarshaler.
592632func (ev * EnvMapBool ) UnmarshalJSON (b []byte ) error {
593633 type Plain EnvMapBool
@@ -625,11 +665,3 @@ func (ev EnvMapBool) Get() (map[string]bool, error) {
625665
626666 return ev .Value , nil
627667}
628-
629- func getEnvVariableValueRequiredError (envName * string ) error {
630- if envName != nil {
631- return fmt .Errorf ("%s: %w" , * envName , ErrEnvironmentVariableValueRequired )
632- }
633-
634- return ErrEnvironmentVariableValueRequired
635- }
0 commit comments