2024-12-22 19:43:53 +09:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
2025-02-16 16:44:00 +09:00
|
|
|
type (
|
|
|
|
|
ctxMergeKey struct{}
|
|
|
|
|
ctxAnchorKey struct{}
|
|
|
|
|
)
|
2024-12-22 19:43:53 +09:00
|
|
|
|
|
|
|
|
func withMerge(ctx context.Context) context.Context {
|
|
|
|
|
return context.WithValue(ctx, ctxMergeKey{}, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isMerge(ctx context.Context) bool {
|
|
|
|
|
v, ok := ctx.Value(ctxMergeKey{}).(bool)
|
|
|
|
|
if !ok {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return v
|
|
|
|
|
}
|
2025-02-16 16:44:00 +09:00
|
|
|
|
|
|
|
|
func withAnchor(ctx context.Context, name string) context.Context {
|
|
|
|
|
anchorMap := getAnchorMap(ctx)
|
|
|
|
|
if anchorMap == nil {
|
|
|
|
|
anchorMap = make(map[string]struct{})
|
|
|
|
|
}
|
|
|
|
|
anchorMap[name] = struct{}{}
|
|
|
|
|
return context.WithValue(ctx, ctxAnchorKey{}, anchorMap)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getAnchorMap(ctx context.Context) map[string]struct{} {
|
|
|
|
|
v, ok := ctx.Value(ctxAnchorKey{}).(map[string]struct{})
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return v
|
|
|
|
|
}
|