| 1 | package yaml |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | type ( |
| 6 | ctxMergeKey struct{} |
| 7 | ctxAnchorKey struct{} |
| 8 | ) |
| 9 | |
| 10 | func withMerge(ctx context.Context) context.Context { |
| 11 | return context.WithValue(ctx, ctxMergeKey{}, true) |
| 12 | } |
| 13 | |
| 14 | func isMerge(ctx context.Context) bool { |
| 15 | v, ok := ctx.Value(ctxMergeKey{}).(bool) |
| 16 | if !ok { |
| 17 | return false |
| 18 | } |
| 19 | return v |
| 20 | } |
| 21 | |
| 22 | func withAnchor(ctx context.Context, name string) context.Context { |
| 23 | anchorMap := getAnchorMap(ctx) |
| 24 | if anchorMap == nil { |
| 25 | anchorMap = make(map[string]struct{}) |
| 26 | } |
| 27 | anchorMap[name] = struct{}{} |
| 28 | return context.WithValue(ctx, ctxAnchorKey{}, anchorMap) |
| 29 | } |
| 30 | |
| 31 | func getAnchorMap(ctx context.Context) map[string]struct{} { |
| 32 | v, ok := ctx.Value(ctxAnchorKey{}).(map[string]struct{}) |
| 33 | if !ok { |
| 34 | return nil |
| 35 | } |
| 36 | return v |
| 37 | } |