Skip to content

Commit

Permalink
Allowing ATHENS_GO_BINARY_ENV_VARS to have multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
arschles committed Dec 20, 2019
1 parent c695a41 commit 2281bd0
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,37 @@ func (el *EnvList) Add(key, value string) {
*el = append(*el, key+"="+value)
}

// Decode implements envconfig.Decoder. Please see the below link for more information on
// that interface:
//
// https://github.com/kelseyhightower/envconfig#custom-decoders
//
// We are doing this to allow for very long lists of assignments to be set inside of
// a single environment variable. For example:
//
// ATHENS_GO_BINARY_ENV_VARS="GOPRIVATE=*.corp.example.com,rsc.io/private;GOPROXY=direct"
//
// See the below link for more information:
// https://github.com/gomods/athens/issues/1404
func (el *EnvList) Decode(value string) error {
const op errors.Op = "envList.Decode"
assignments := strings.Split(value, ";")
fmt.Printf("%s assignments = %#v\n", op, assignments)
fmt.Printf("envlist: %#v\n", *el)
for _, assignment := range assignments {
kv := strings.Split(assignment, "=")
if len(kv) != 2 {
return errors.E(
op,
errors.KindBadRequest,
fmt.Errorf("environment variable assignment %s is invalid", assignment),
)
}
el.Add(kv[0], kv[1])
}
return nil
}

// Validate validates that all strings inside the
// list are of the key=value format
func (el EnvList) Validate() error {
Expand Down

0 comments on commit 2281bd0

Please sign in to comment.