about summary refs log tree commit diff stats
path: root/internal/importer
diff options
context:
space:
mode:
Diffstat (limited to 'internal/importer')
-rw-r--r--internal/importer/channel.go3
-rw-r--r--internal/importer/importer.go11
-rw-r--r--internal/importer/ingest.go5
-rw-r--r--internal/importer/nixpkgs-channel.go3
-rw-r--r--internal/importer/repository.go44
-rw-r--r--internal/importer/source-type.go60
6 files changed, 15 insertions, 111 deletions
diff --git a/internal/importer/channel.go b/internal/importer/channel.go
index 70aa9de..fb6668c 100644
--- a/internal/importer/channel.go
+++ b/internal/importer/channel.go
@@ -7,6 +7,7 @@ import (
 	"os"
 	"os/exec"
 	"path"
+	"searchix/internal/config"
 	"searchix/internal/file"
 	"searchix/internal/search"
 	"strconv"
@@ -17,7 +18,7 @@ import (
 
 type ChannelImporter struct {
 	DataPath   string
-	Source     *Source
+	Source     *config.Source
 	SourceFile string
 	Logger     *slog.Logger
 }
diff --git a/internal/importer/importer.go b/internal/importer/importer.go
index 0f7978d..5f251b0 100644
--- a/internal/importer/importer.go
+++ b/internal/importer/importer.go
@@ -4,6 +4,7 @@ import (
 	"context"
 	"log/slog"
 	"path"
+	"searchix/internal/config"
 	"searchix/internal/search"
 	"sync"
 )
@@ -14,7 +15,7 @@ type Importer interface {
 }
 
 func NewNixpkgsChannelImporter(
-	source *Source,
+	source *config.Source,
 	dataPath string,
 	logger *slog.Logger,
 ) *NixpkgsChannelImporter {
@@ -27,7 +28,11 @@ func NewNixpkgsChannelImporter(
 	}
 }
 
-func NewChannelImporter(source *Source, dataPath string, logger *slog.Logger) *ChannelImporter {
+func NewChannelImporter(
+	source *config.Source,
+	dataPath string,
+	logger *slog.Logger,
+) *ChannelImporter {
 	fullpath := path.Join(dataPath, source.Channel)
 
 	return &ChannelImporter{
@@ -39,7 +44,7 @@ func NewChannelImporter(source *Source, dataPath string, logger *slog.Logger) *C
 
 type importConfig struct {
 	Filename string
-	Source   *Source
+	Source   *config.Source
 	Logger   *slog.Logger
 }
 
diff --git a/internal/importer/ingest.go b/internal/importer/ingest.go
index 7706807..f78722a 100644
--- a/internal/importer/ingest.go
+++ b/internal/importer/ingest.go
@@ -7,6 +7,7 @@ import (
 	"net/url"
 	"os"
 	"reflect"
+	"searchix/internal/config"
 	"searchix/internal/options"
 
 	"github.com/bcicen/jstream"
@@ -108,14 +109,14 @@ type OptionIngester struct {
 	ms      *mapstructure.Decoder
 	optJSON nixOptionJSON
 	infile  *os.File
-	source  *Source
+	source  *config.Source
 }
 
 type Ingester[T options.NixOption] interface {
 	Process() (<-chan *T, <-chan error)
 }
 
-func NewOptionProcessor(inpath string, source *Source) (*OptionIngester, error) {
+func NewOptionProcessor(inpath string, source *config.Source) (*OptionIngester, error) {
 	infile, err := os.Open(inpath)
 	if err != nil {
 		return nil, errors.WithMessagef(err, "failed to open input file %s", inpath)
diff --git a/internal/importer/nixpkgs-channel.go b/internal/importer/nixpkgs-channel.go
index 2ee6027..7aaa816 100644
--- a/internal/importer/nixpkgs-channel.go
+++ b/internal/importer/nixpkgs-channel.go
@@ -7,6 +7,7 @@ import (
 	"net/url"
 	"os"
 	"path"
+	"searchix/internal/config"
 	"searchix/internal/file"
 	"searchix/internal/search"
 
@@ -15,7 +16,7 @@ import (
 
 type NixpkgsChannelImporter struct {
 	DataPath string
-	Source   *Source
+	Source   *config.Source
 	Logger   *slog.Logger
 }
 
diff --git a/internal/importer/repository.go b/internal/importer/repository.go
deleted file mode 100644
index 6cfd55e..0000000
--- a/internal/importer/repository.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package importer
-
-import (
-	"fmt"
-	"strings"
-)
-
-type RepoType int
-
-const (
-	GitHub = iota + 1
-)
-
-type Repository struct {
-	Type     string `default:"github"`
-	Owner    string
-	Repo     string
-	Revision string
-}
-
-func (f RepoType) String() string {
-	switch f {
-	case GitHub:
-		return "github"
-	default:
-		return fmt.Sprintf("RepoType(%d)", f)
-	}
-}
-
-func parseRepoType(name string) (RepoType, error) {
-	switch strings.ToLower(name) {
-	case "github":
-		return GitHub, nil
-	default:
-		return Unknown, fmt.Errorf("unsupported repo type %s", name)
-	}
-}
-
-func (f *RepoType) UnmarshalText(text []byte) error {
-	var err error
-	*f, err = parseRepoType(string(text))
-
-	return err
-}
diff --git a/internal/importer/source-type.go b/internal/importer/source-type.go
deleted file mode 100644
index 0e9bb73..0000000
--- a/internal/importer/source-type.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package importer
-
-import (
-	"fmt"
-	"time"
-
-	"github.com/stoewer/go-strcase"
-)
-
-type Type int
-
-const (
-	Unknown = iota
-	Channel
-	ChannelNixpkgs
-)
-
-func (f Type) String() string {
-	switch f {
-	case Channel:
-		return "channel"
-	case ChannelNixpkgs:
-		return "channel-nixpkgs"
-	}
-
-	return fmt.Sprintf("Fetcher(%d)", f)
-}
-
-func parseType(name string) (Type, error) {
-	switch strcase.KebabCase(name) {
-	case "channel":
-		return Channel, nil
-	case "channel-nixpkgs":
-		return ChannelNixpkgs, nil
-	default:
-		return Unknown, fmt.Errorf("unsupported fetcher %s", name)
-	}
-}
-
-func (f *Type) UnmarshalText(text []byte) error {
-	var err error
-	*f, err = parseType(string(text))
-
-	return err
-}
-
-type Source struct {
-	Name          string
-	Key           string
-	Enable        bool
-	Type          Type
-	Channel       string
-	URL           string
-	Attribute     string
-	ImportPath    string        `toml:"import-path"`
-	FetchTimeout  time.Duration `toml:"fetch-timeout"`
-	ImportTimeout time.Duration `toml:"import-timeout"`
-	OutputPath    string        `toml:"output-path"`
-	Repo          Repository
-}