mirror of
https://github.com/caddyserver/caddy.git
synced 2026-01-16 17:20:34 +00:00
chore: Bump up to Go 1.19, minimum 1.18 (#4925)
This commit is contained in:
20
replacer.go
20
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.
|
||||
|
||||
Reference in New Issue
Block a user