mirror of
https://github.com/traefik/traefik.git
synced 2026-02-03 20:39:51 -05:00
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Build and Publish Documentation / Doc Process (push) Waiting to run
Build experimental image on branch / build-webui (push) Waiting to run
Build experimental image on branch / Build experimental image on branch (push) Waiting to run
26 lines
622 B
Go
26 lines
622 B
Go
package recursion
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
type stackType int
|
|
|
|
const (
|
|
stackKey stackType = iota
|
|
)
|
|
|
|
func CheckRecursion(ctx context.Context, itemType, itemName string) (context.Context, error) {
|
|
currentStack, ok := ctx.Value(stackKey).([]string)
|
|
if !ok {
|
|
currentStack = []string{}
|
|
}
|
|
name := itemType + ":" + itemName
|
|
if slices.Contains(currentStack, name) {
|
|
return ctx, fmt.Errorf("could not instantiate %s %s: recursion detected in %s", itemType, itemName, strings.Join(append(currentStack, name), "->"))
|
|
}
|
|
return context.WithValue(ctx, stackKey, append(currentStack, name)), nil
|
|
}
|