Skip to content

Commit

Permalink
refactor: Rename ManifestWriterContext and document symbols
Browse files Browse the repository at this point in the history
Best practice in Go is not to have the package name as a prefix, since it is redundant information in the usage.
  • Loading branch information
Laubi committed Mar 20, 2023
1 parent f91dcd1 commit 1241592
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/manifest/manifest_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1241592

Please sign in to comment.