From 124159280bb2eae7bcb917e35e2f74fcabf4e644 Mon Sep 17 00:00:00 2001 From: David Laubreiter Date: Fri, 17 Mar 2023 11:41:51 +0100 Subject: [PATCH] refactor: Rename ManifestWriterContext and document symbols Best practice in Go is not to have the package name as a prefix, since it is redundant information in the usage. --- pkg/manifest/manifest_writer.go | 12 ++++++++---- pkg/writer/writer.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/manifest/manifest_writer.go b/pkg/manifest/manifest_writer.go index 7dadad079..384357e5e 100644 --- a/pkg/manifest/manifest_writer.go +++ b/pkg/manifest/manifest_writer.go @@ -23,12 +23,16 @@ import ( "gopkg.in/yaml.v2" ) -type ManifestWriterContext struct { - Fs afero.Fs +// WriterContext holds all information for [WriteManifest] +type WriterContext struct { + // Fs holds the abstraction of the file system. + Fs afero.Fs + + // ManifestPath holds the path from where the manifest should be written to. ManifestPath string } -func WriteManifest(context *ManifestWriterContext, manifestToWrite Manifest) error { +func WriteManifest(context *WriterContext, manifestToWrite Manifest) error { sanitizedPath := filepath.Clean(context.ManifestPath) folder := filepath.Dir(sanitizedPath) @@ -52,7 +56,7 @@ func WriteManifest(context *ManifestWriterContext, manifestToWrite Manifest) err return persistManifestToDisk(context, m) } -func persistManifestToDisk(context *ManifestWriterContext, m manifest) error { +func persistManifestToDisk(context *WriterContext, m manifest) error { manifestAsYaml, err := yaml.Marshal(m) if err != nil { diff --git a/pkg/writer/writer.go b/pkg/writer/writer.go index 120cdaa00..1f1be2820 100644 --- a/pkg/writer/writer.go +++ b/pkg/writer/writer.go @@ -41,7 +41,7 @@ func WriteToDisk(context *WriterContext, manifestToWrite manifest.Manifest, proj return []error{err} } - err = manifest.WriteManifest(&manifest.ManifestWriterContext{ + err = manifest.WriteManifest(&manifest.WriterContext{ Fs: context.Fs, ManifestPath: filepath.Join(sanitizedOutputDir, context.ManifestName), }, manifestToWrite)