readGlobalConfigNode reads the YAML document from the given path. Returns an empty document if the file does not exist.
(path string)
| 178 | // readGlobalConfigNode reads the YAML document from the given path. |
| 179 | // Returns an empty document if the file does not exist. |
| 180 | func readGlobalConfigNode(path string) (*yaml.Node, error) { |
| 181 | data, err := os.ReadFile(path) |
| 182 | if os.IsNotExist(err) { |
| 183 | return emptyDocNode(), nil |
| 184 | } |
| 185 | if err != nil { |
| 186 | return nil, err |
| 187 | } |
| 188 | if len(data) == 0 { |
| 189 | return emptyDocNode(), nil |
| 190 | } |
| 191 | var doc yaml.Node |
| 192 | if err := yaml.Unmarshal(data, &doc); err != nil { |
| 193 | return nil, fmt.Errorf("failed to parse %s: %w", path, err) |
| 194 | } |
| 195 | return &doc, nil |
| 196 | } |
| 197 | |
| 198 | func emptyDocNode() *yaml.Node { |
| 199 | return &yaml.Node{ |