summaryrefslogtreecommitdiff
path: root/replacer.go
diff options
context:
space:
mode:
Diffstat (limited to 'replacer.go')
-rw-r--r--replacer.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/replacer.go b/replacer.go
index bffc424..b8b2267 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.