1+
12package dockerimageprocessing
23
34import (
@@ -15,6 +16,7 @@ type ImageInfo struct {
1516 logger * zap.Logger
1617}
1718
19+ // NewImageInfo initializes a new ImageInfo instance with a map and a logger.
1820func NewImageInfo () * ImageInfo {
1921 // Initialize the zap logger
2022 logger , _ := zap .NewProduction ()
@@ -25,20 +27,23 @@ func NewImageInfo() *ImageInfo {
2527 }
2628}
2729
30+ // UnmarshalYAML is a method that unmarshals YAML data into a map and finds images in it.
2831func (ii * ImageInfo ) UnmarshalYAML (data []byte ) error {
2932 var values map [string ]interface {}
3033 if err := yaml .Unmarshal (data , & values ); err != nil {
31- ii .logger .Error (" Failed to unmarshal YAML!" , zap .Error (err ))
34+ ii .logger .Error ("Failed to unmarshal YAML !" , zap .Error (err ))
3235 return err
3336 }
3437 ii .findImages (values , "" , & ii .Images )
3538 return nil
3639}
3740
41+ // MarshalJSON is a method that marshals the Images map into JSON format.
3842func (ii * ImageInfo ) MarshalJSON () ([]byte , error ) {
3943 return json .Marshal (ii .Images )
4044}
4145
46+ // Node is a struct that represents a node in a tree. It contains the node's value and path.
4247type Node struct {
4348 Value interface {}
4449 Path string
@@ -47,7 +52,7 @@ type Node struct {
4752// findImages is a method of the ImageInfo struct that traverses a given node tree
4853// (represented as an interface{}) in search of image specifications.
4954// The method uses a stack to perform a depth-first search of the tree.
50- // If an image specification is found, its path and corresponding image path are logged and stored in the images map.
55+ // If an image specification is found, its path and corresponding image path are logged and stored in the Images map.
5156// The method also handles nested structures, such as maps and slices, by iterating over their elements and pushing them to the stack.
5257//
5358// Parameters:
@@ -70,9 +75,9 @@ func (ii *ImageInfo) findImages(node interface{}, path string, images *map[strin
7075 imagePath , isImage := ii .constructImagePath (node )
7176 if isImage {
7277 ii .logger .Info ("Found docker Image Specification:" , zap .String ("path" , currentNode .Path + ".tag" ), zap .String ("imagePath" , imagePath ))
73- // Access the slice of strings stored in the map 'images' using 'imagePath' as the key.
78+ // Access the slice of strings stored in the Images map using 'imagePath' as the key.
7479 // Append the value of 'currentNode.Path' concatenated with ".tag" to this slice.
75- // Store the updated slice back in the map at the same key.
80+ // Store the updated slice back in the Images map at the same key.
7681 (* images )[imagePath ] = append ((* images )[imagePath ], currentNode .Path + ".tag" )
7782
7883 continue // Found an image specification, no need to go deeper in this branch
@@ -92,7 +97,7 @@ func (ii *ImageInfo) findImages(node interface{}, path string, images *map[strin
9297 }
9398}
9499
95- // Helper function to construct the full image path if possible
100+ // constructImagePath is a helper function that constructs the full image path if possible.
96101func (ii * ImageInfo ) constructImagePath (node map [string ]interface {}) (string , bool ) {
97102 registry , hasRegistry := node ["registry" ].(string )
98103 repository , hasRepository := node ["repository" ].(string )
@@ -104,12 +109,10 @@ func (ii *ImageInfo) constructImagePath(node map[string]interface{}) (string, bo
104109 return "" , false
105110}
106111
107- // Helper function to append new segments to a path
112+ // appendPath is a helper function to append new segments to a path.
108113func (ii * ImageInfo ) appendPath (basePath , addition string ) string {
109114 if basePath == "" {
110115 return addition
111116 }
112117 return basePath + "." + addition
113118}
114-
115- // findImages and appendPath functions remain unchanged, but are methods of ImageInfo struct.
0 commit comments