diff options
author | Alan Pearce | 2024-05-16 20:22:42 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-16 20:31:03 +0200 |
commit | c51ca7c62e08f43ef9974af35886d30ce54a1f22 (patch) | |
tree | 6779f521c289d1750ceb35b57fbb0d3acad20385 /internal/importer/package.go | |
parent | 0ef52f2f82c62694c5420f7f6c82fb8c45900d1d (diff) | |
download | searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.lz searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.zst searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.zip |
refactor: use interface to unify Options and Packages
Diffstat (limited to 'internal/importer/package.go')
-rw-r--r-- | internal/importer/package.go | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/internal/importer/package.go b/internal/importer/package.go index c0f5f93..a1bc9fb 100644 --- a/internal/importer/package.go +++ b/internal/importer/package.go @@ -7,7 +7,7 @@ import ( "os" "reflect" "searchix/internal/config" - "searchix/internal/packages" + "searchix/internal/nix" "strings" "github.com/bcicen/jstream" @@ -45,8 +45,8 @@ type PackageIngester struct { source *config.Source } -func makeAdhocLicense(name string) packages.License { - return packages.License{ +func makeAdhocLicense(name string) nix.License { + return nix.License{ FullName: name, } } @@ -88,8 +88,8 @@ func NewPackageProcessor(inpath string, source *config.Source) (*PackageIngester return i, nil } -func convertToLicense(in map[string]any) *packages.License { - l := &packages.License{} +func convertToLicense(in map[string]any) *nix.License { + l := &nix.License{} if v, found := in["shortName"]; found { l.Name = v.(string) } @@ -109,8 +109,10 @@ func convertToLicense(in map[string]any) *packages.License { return l } -func (i *PackageIngester) Process(ctx context.Context) (<-chan *packages.Package, <-chan error) { - results := make(chan *packages.Package) +func (i *PackageIngester) Process( + ctx context.Context, +) (<-chan nix.Importable, <-chan error) { + results := make(chan nix.Importable) errs := make(chan error) go func() { @@ -143,13 +145,13 @@ func (i *PackageIngester) Process(ctx context.Context) (<-chan *packages.Package meta := x["meta"].(map[string]interface{}) - var licenses []packages.License + var licenses []nix.License if meta["license"] != nil { switch v := reflect.ValueOf(meta["license"]); v.Kind() { case reflect.Map: licenses = append(licenses, *convertToLicense(v.Interface().(map[string]interface{}))) case reflect.Array, reflect.Slice: - licenses = make([]packages.License, v.Len()) + licenses = make([]nix.License, v.Len()) for i, v := range v.Interface().([]interface{}) { switch v := reflect.ValueOf(v); v.Kind() { case reflect.String: @@ -214,9 +216,9 @@ func (i *PackageIngester) Process(ctx context.Context) (<-chan *packages.Package continue } - maintainers := make([]packages.Maintainer, len(i.pkg.Meta.Maintainers)) + maintainers := make([]nix.Maintainer, len(i.pkg.Meta.Maintainers)) for i, m := range i.pkg.Meta.Maintainers { - maintainers[i] = packages.Maintainer{ + maintainers[i] = nix.Maintainer{ Name: m.Name, Github: m.Github, } @@ -224,20 +226,19 @@ func (i *PackageIngester) Process(ctx context.Context) (<-chan *packages.Package subpath, line, _ := strings.Cut(i.pkg.Meta.Position, ":") - results <- &packages.Package{ - Name: i.pkg.Name, - Version: i.pkg.Version, - Meta: packages.Meta{ - Broken: i.pkg.Meta.Broken, - Description: i.pkg.Meta.Description, - LongDescription: i.pkg.Meta.LongDescription, - Homepages: i.pkg.Meta.Homepages, - Licenses: licenses, - MainProgram: i.pkg.Meta.MainProgram, - Platforms: i.pkg.Meta.Platforms, - Maintainers: maintainers, - Position: makeGitHubFileURL(userRepo, "", subpath, line), - }, + results <- nix.Package{ + Name: i.pkg.Name, + Source: i.source.Key, + Version: i.pkg.Version, + Broken: i.pkg.Meta.Broken, + Description: i.pkg.Meta.Description, + LongDescription: i.pkg.Meta.LongDescription, + Homepages: i.pkg.Meta.Homepages, + MainProgram: i.pkg.Meta.MainProgram, + Platforms: i.pkg.Meta.Platforms, + Licenses: licenses, + Maintainers: maintainers, + Definition: makeGitHubFileURL(userRepo, "", subpath, line), } } }() |