From 3e2356a3f68c7333c04aa156752a4c4ffba71a7e Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sat, 26 Jun 2021 20:34:39 +0100 Subject: [PATCH] envexp: turn Expander from interface to struct Signed-off-by: Alejandro Mery --- envexp/expand.go | 14 +++++--------- envexp/global.go | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/envexp/expand.go b/envexp/expand.go index c05a84c..41ccdc6 100644 --- a/envexp/expand.go +++ b/envexp/expand.go @@ -10,34 +10,30 @@ import ( type VarGetter func(key string) string // A Expander is an object that you can use to Expand strings -type Expander interface { - Expand(s string) string -} - -type expander struct { +type Expander struct { get VarGetter } // NewExpander allocates a new Expander using a // given VarGetter, or os.Getenv if none is given -func NewExpander(f VarGetter) Expander { +func NewExpander(f VarGetter) *Expander { if f == nil { f = os.Getenv } - return &expander{ + return &Expander{ get: f, } } // Get resolves a variable name as the given Expander // would do -func (exp *expander) Get(key string) string { +func (exp *Expander) Get(key string) string { return exp.get(key) } // Expand expands a string using the VarGetter // defined for the given Expander -func (exp *expander) Expand(s string) string { +func (exp *Expander) Expand(s string) string { return s } diff --git a/envexp/global.go b/envexp/global.go index f5ce294..f80ad78 100644 --- a/envexp/global.go +++ b/envexp/global.go @@ -4,7 +4,7 @@ import ( "os" ) -var envExpander = &expander{ +var envExpander = &Expander{ get: os.Getenv, }