Skip to content

Commit

Permalink
better slice support
Browse files Browse the repository at this point in the history
  • Loading branch information
profclems committed Sep 10, 2024
1 parent 86e1283 commit edb8dfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
13 changes: 9 additions & 4 deletions dotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,19 @@ func (e *DotEnv) GetDuration(key string) time.Duration {
func GetIntSlice(key string) []int { return d.GetIntSlice(key) }

func (e *DotEnv) GetIntSlice(key string) []int {
return cast.ToIntSlice(e.Get(key))
return cast.ToIntSlice(toSlice(e.GetString(key)))
}
func toSlice(value string) []string {
value = strings.TrimPrefix(value, "[")
value = strings.TrimSuffix(value, "]")
return strings.Split(value, ",")
}

// GetStringSlice returns the value associated with the key as a slice of strings.
func GetStringSlice(key string) []string { return d.GetStringSlice(key) }

func (e *DotEnv) GetStringSlice(key string) []string {
return cast.ToStringSlice(e.Get(key))
return cast.ToStringSlice(toSlice(e.GetString(key)))
}

// GetSizeInBytes returns the size of the value associated with the given key
Expand All @@ -362,8 +367,8 @@ func (e *DotEnv) GetSizeInBytes(key string) uint {
func IsSet(key string) bool { return d.IsSet(key) }

func (e *DotEnv) IsSet(key string) bool {
val := e.Get(key)
return val != nil
_, set := e.LookUp(key)
return set
}

// LookUp retrieves the value of the configuration named by the key.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/google/renameio v1.0.1
github.com/spf13/cast v1.7.0
github.com/stretchr/testify v1.9.0
golang.org/x/text v0.18.0
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down

0 comments on commit edb8dfb

Please sign in to comment.