From f85526034745406f35121d889ab195dc307037c2 Mon Sep 17 00:00:00 2001 From: Adam Eijdenberg Date: Wed, 11 Jul 2018 11:19:23 +1000 Subject: [PATCH] Make public some more methods that are useful for consumers of this class --- env/env.go | 8 +++++--- env/ups.go | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/env/env.go b/env/env.go index b6cf639..277428d 100644 --- a/env/env.go +++ b/env/env.go @@ -10,9 +10,11 @@ import ( // and whether or not it was found. type Lookup func(name string) (string, bool) -// passthruLookup always returns false for the environment variable with the -// given name. -func passthruLookup(name string) (string, bool) { +// NoopLookup always returns false for the environment variable with the +// given name. Useful as a fallback to return for an env lookup that may +// not always be applicable, e.g. if not running in CloudFoundry, a user +// provided service lookup won't be applicable. +func NoopLookup(name string) (string, bool) { return "", false } diff --git a/env/ups.go b/env/ups.go index 9eeb50f..453e6f9 100644 --- a/env/ups.go +++ b/env/ups.go @@ -6,27 +6,27 @@ import ( "github.com/cloudfoundry-community/go-cfenv" ) -// WithUPSLookup configures the VarSet to use the Cloud Foundry user-provided +// WithUPSLookup configures the VarSet to use the CloudFoundry user-provided // service with the given name as a lookup source. func WithUPSLookup(app *cfenv.App, name string) VarSetOpt { return func(v *VarSet) { - v.AppendSource(newLookupFromUPS(app, name)) + v.AppendSource(NewLookupFromUPS(app, name)) } } -// newLookupFromUPS looks for a Cloud Foundry bound service with the given name. +// NewLookupFromUPS looks for a CloudFoundry bound service with the given name. // This allows sourcing environment variables from a user-provided service. // If no service is found, a passthrough lookup is used that always returns // false. -func newLookupFromUPS(app *cfenv.App, name string) Lookup { +func NewLookupFromUPS(app *cfenv.App, name string) Lookup { if app == nil { - return passthruLookup + return NoopLookup } service, err := app.Services.WithName(name) // The only error WithName will return is that the service was not found, // so it is OK that we ignore the error here. if err != nil { - return passthruLookup + return NoopLookup } return func(k string) (string, bool) { v, ok := service.Credentials[k]