FirstMatchingBlock returns a first matching block from the body that has the given name and labels or returns nil if there is currently no matching block.
(typeName string, labels []string)
| 122 | // given name and labels or returns nil if there is currently no matching |
| 123 | // block. |
| 124 | func (b *Body) FirstMatchingBlock(typeName string, labels []string) *Block { |
| 125 | for _, block := range b.Blocks() { |
| 126 | if typeName == block.Type() { |
| 127 | labelNames := block.Labels() |
| 128 | if len(labels) == 0 && len(labelNames) == 0 { |
| 129 | return block |
| 130 | } |
| 131 | if reflect.DeepEqual(labels, labelNames) { |
| 132 | return block |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | // RemoveBlock removes the given block from the body, if it's in that body. |
| 141 | // If it isn't present, this is a no-op. |