Skip to content

Commit

Permalink
change maps for structs with omitempty, jsonwall iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
letFunny committed Jul 10, 2024
1 parent e2c2645 commit 140ab91
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import (

type Package struct {
Kind string `json:"kind"`
Name string `json:"name"`
Version string `json:"version"`
Digest string `json:"sha256"`
Arch string `json:"arch"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Digest string `json:"sha256,omitempty"`
Arch string `json:"arch,omitempty"`
}

type Slice struct {
Kind string `json:"kind"`
Name string `json:"name"`
Name string `json:"name,omitempty"`
}

type Path struct {
Kind string `json:"kind"`
Path string `json:"path"`
Mode string `json:"mode"`
Slices []string `json:"slices"`
Path string `json:"path,omitempty"`
Mode string `json:"mode,omitempty"`
Slices []string `json:"slices,omitempty"`
Hash string `json:"sha256,omitempty"`
FinalHash string `json:"final_sha256,omitempty"`
Size uint64 `json:"size,omitempty"`
Expand All @@ -37,8 +37,8 @@ type Path struct {

type Content struct {
Kind string `json:"kind"`
Slice string `json:"slice"`
Path string `json:"path"`
Slice string `json:"slice,omitempty"`
Path string `json:"path,omitempty"`
}

type Manifest struct {
Expand Down Expand Up @@ -79,14 +79,7 @@ func (manifest *Manifest) IteratePath(pathPrefix string, f func(Path) error) (er
}
}()

prefix := struct {
Kind string `json:"kind"`
Path string `json:"path"`
}{
Kind: "path",
Path: pathPrefix,
}
iter, err := manifest.db.IteratePrefix(prefix)
iter, err := manifest.db.IteratePrefix(Path{Kind: "path", Path: pathPrefix})
if err != nil {
return err
}
Expand All @@ -111,7 +104,7 @@ func (manifest *Manifest) IteratePackages(f func(Package) error) (err error) {
}
}()

iter, err := manifest.db.Iterate(map[string]string{"kind": "package"})
iter, err := manifest.db.Iterate(Package{Kind: "package"})
if err != nil {
return err
}
Expand All @@ -136,14 +129,7 @@ func (manifest *Manifest) IterateSlices(pkgName string, f func(Slice) error) (er
}
}()

prefix := struct {
Kind string `json:"kind"`
Name string `json:"name"`
}{
Kind: "slice",
Name: pkgName,
}
iter, err := manifest.db.IteratePrefix(&prefix)
iter, err := manifest.db.IteratePrefix(Slice{Kind: "slice", Name: pkgName})
if err != nil {
return err
}
Expand Down Expand Up @@ -172,7 +158,7 @@ func Validate(manifest *Manifest) (err error) {
}()

pkgExist := map[string]bool{}
iter, err := manifest.db.Iterate(map[string]string{"kind": "package"})
iter, err := manifest.db.Iterate(Package{Kind: "package"})
if err != nil {
return err
}
Expand All @@ -186,7 +172,7 @@ func Validate(manifest *Manifest) (err error) {
}

sliceExist := map[string]bool{}
iter, err = manifest.db.Iterate(map[string]string{"kind": "slice"})
iter, err = manifest.db.Iterate(Slice{Kind: "slice"})
if err != nil {
return err
}
Expand All @@ -207,7 +193,7 @@ func Validate(manifest *Manifest) (err error) {
}

pathToSlices := map[string][]string{}
iter, err = manifest.db.Iterate(map[string]string{"kind": "content"})
iter, err = manifest.db.Iterate(Content{Kind: "content"})
if err != nil {
return err
}
Expand All @@ -223,7 +209,7 @@ func Validate(manifest *Manifest) (err error) {
pathToSlices[content.Path] = append(pathToSlices[content.Path], content.Slice)
}

iter, err = manifest.db.Iterate(map[string]string{"kind": "path"})
iter, err = manifest.db.Iterate(Path{Kind: "path"})
if err != nil {
return err
}
Expand Down

0 comments on commit 140ab91

Please sign in to comment.