MCPcopy
hub / github.com/docker/compose / getMapping

Function getMapping

pkg/compose/transform/replace.go:109–123  ·  view source on GitHub ↗
(root *yaml.Node, key string)

Source from the content-addressed store, hash-verified

107}
108
109func getMapping(root *yaml.Node, key string) (*yaml.Node, error) {
110 var node *yaml.Node
111 l := len(root.Content)
112 for i := 0; i < l; i += 2 {
113 k := root.Content[i]
114 if k.Kind != yaml.ScalarNode || k.Tag != "!!str" {
115 return nil, fmt.Errorf("expected mapping key to be a string, got %v %v", root.Kind, k.Tag)
116 }
117 if k.Value == key {
118 node = root.Content[i+1]
119 return node, nil
120 }
121 }
122 return nil, fmt.Errorf("key %v not found", key)
123}
124
125// replace changes yaml node value in stream at position, preserving content
126func replace(in []byte, line int, column int, value string) []byte {

Callers 2

ReplaceExtendsFileFunction · 0.85
ReplaceEnvFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected