about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-06-09 15:26:17 +0200
committerAlan Pearce2024-06-09 15:26:17 +0200
commit789d0079f84017ddafad763ffba9aadbcd6aa6da (patch)
treec18ed4c24d35ef038a9d2deeb77d5a8f584fa55e
parenta495a673d2dda7b2aa9b11217d4662367a627517 (diff)
downloadsearchix-789d0079f84017ddafad763ffba9aadbcd6aa6da.tar.lz
searchix-789d0079f84017ddafad763ffba9aadbcd6aa6da.tar.zst
searchix-789d0079f84017ddafad763ffba9aadbcd6aa6da.zip
refactor: use a struct to configure index options
-rw-r--r--cmd/searchix-web/main.go5
-rw-r--r--searchix.go22
2 files changed, 19 insertions, 8 deletions
diff --git a/cmd/searchix-web/main.go b/cmd/searchix-web/main.go
index c9ba2d6..5ece329 100644
--- a/cmd/searchix-web/main.go
+++ b/cmd/searchix-web/main.go
@@ -55,7 +55,10 @@ func main() {
 		log.Fatalf("Failed to initialise searchix: %v", err)
 	}
 
-	err = s.SetupIndex(*update, *replace)
+	err = s.SetupIndex(&searchix.IndexOptions{
+		Update:  *update,
+		Replace: *replace,
+	})
 	if err != nil {
 		log.Fatalf("Failed to setup index: %v", err)
 	}
diff --git a/searchix.go b/searchix.go
index b53ccfb..9ea7b9a 100644
--- a/searchix.go
+++ b/searchix.go
@@ -38,7 +38,12 @@ func nextOccurrenceOfLocalTime(t toml.LocalTime) time.Time {
 	return nextRun
 }
 
-func (s *Server) SetupIndex(update bool, replace bool) error {
+type IndexOptions struct {
+	Update  bool
+	Replace bool
+}
+
+func (s *Server) SetupIndex(options *IndexOptions) error {
 	var i uint
 	cfgEnabledSources := make([]string, len(s.cfg.Importer.Sources))
 	for key := range s.cfg.Importer.Sources {
@@ -47,28 +52,31 @@ func (s *Server) SetupIndex(update bool, replace bool) error {
 	}
 	slices.Sort(cfgEnabledSources)
 
-	read, write, exists, err := index.OpenOrCreate(s.cfg.DataPath, replace)
+	read, write, exists, err := index.OpenOrCreate(
+		s.cfg.DataPath,
+		options.Replace,
+	)
 	if err != nil {
 		return errors.Wrap(err, "Failed to open or create index")
 	}
 	s.readIndex = read
 	s.writeIndex = write
 
-	if !exists || replace || update {
+	if !exists || options.Replace || options.Update {
 		slog.Info(
 			"Starting build job",
 			"new",
 			!exists,
 			"replace",
-			replace,
+			options.Replace,
 			"update",
-			update,
+			options.Update,
 		)
-		err = importer.Start(s.cfg, write, replace || update, nil)
+		err = importer.Start(s.cfg, write, options.Replace || options.Update, nil)
 		if err != nil {
 			return errors.Wrap(err, "Failed to build index")
 		}
-		if replace || update {
+		if options.Replace || options.Update {
 			return nil
 		}
 	} else {