diff options
author | Francis Lavoie <[email protected]> | 2022-08-02 16:39:09 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2022-08-02 16:39:09 -0400 |
commit | 141872ed80d6323505e7543628c259fdae8506d3 (patch) | |
tree | 53581cddf2fcce189c3a55019194b64b0cd3af13 /replacer.go | |
parent | db1aa5b5bc174e5a5df39a277f737b304e1e2350 (diff) | |
download | caddy-141872ed80d6323505e7543628c259fdae8506d3.tar.gz caddy-141872ed80d6323505e7543628c259fdae8506d3.zip |
chore: Bump up to Go 1.19, minimum 1.18 (#4925)
Diffstat (limited to 'replacer.go')
-rw-r--r-- | replacer.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/replacer.go b/replacer.go index bffc42448..b8b226712 100644 --- a/replacer.go +++ b/replacer.go @@ -27,7 +27,7 @@ import ( // NewReplacer returns a new Replacer. func NewReplacer() *Replacer { rep := &Replacer{ - static: make(map[string]interface{}), + static: make(map[string]any), } rep.providers = []ReplacerFunc{ globalDefaultReplacements, @@ -40,7 +40,7 @@ func NewReplacer() *Replacer { // without the global default replacements. func NewEmptyReplacer() *Replacer { rep := &Replacer{ - static: make(map[string]interface{}), + static: make(map[string]any), } rep.providers = []ReplacerFunc{ rep.fromStatic, @@ -53,7 +53,7 @@ func NewEmptyReplacer() *Replacer { // use NewReplacer to make one. type Replacer struct { providers []ReplacerFunc - static map[string]interface{} + static map[string]any } // Map adds mapFunc to the list of value providers. @@ -63,13 +63,13 @@ func (r *Replacer) Map(mapFunc ReplacerFunc) { } // Set sets a custom variable to a static value. -func (r *Replacer) Set(variable string, value interface{}) { +func (r *Replacer) Set(variable string, value any) { r.static[variable] = value } // Get gets a value from the replacer. It returns // the value and whether the variable was known. -func (r *Replacer) Get(variable string) (interface{}, bool) { +func (r *Replacer) Get(variable string) (any, bool) { for _, mapFunc := range r.providers { if val, ok := mapFunc(variable); ok { return val, true @@ -92,7 +92,7 @@ func (r *Replacer) Delete(variable string) { } // fromStatic provides values from r.static. -func (r *Replacer) fromStatic(key string) (interface{}, bool) { +func (r *Replacer) fromStatic(key string) (any, bool) { val, ok := r.static[key] return val, ok } @@ -230,7 +230,7 @@ scan: return sb.String(), nil } -func toString(val interface{}) string { +func toString(val any) string { switch v := val.(type) { case nil: return "" @@ -275,9 +275,9 @@ func toString(val interface{}) string { // to service that key (even if the value is blank). If the // function does not recognize the key, false should be // returned. -type ReplacerFunc func(key string) (interface{}, bool) +type ReplacerFunc func(key string) (any, bool) -func globalDefaultReplacements(key string) (interface{}, bool) { +func globalDefaultReplacements(key string) (any, bool) { // check environment variable const envPrefix = "env." if strings.HasPrefix(key, envPrefix) { @@ -316,7 +316,7 @@ func globalDefaultReplacements(key string) (interface{}, bool) { // will be the replacement, and returns the value that // will actually be the replacement, or an error. Note // that errors are sometimes ignored by replacers. -type ReplacementFunc func(variable string, val interface{}) (interface{}, error) +type ReplacementFunc func(variable string, val any) (any, error) // nowFunc is a variable so tests can change it // in order to obtain a deterministic time. |