all repos — searchix @ 789d0079f84017ddafad763ffba9aadbcd6aa6da

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor: use a struct to configure index options

Alan Pearce
commit

789d0079f84017ddafad763ffba9aadbcd6aa6da

parent

a495a673d2dda7b2aa9b11217d4662367a627517

2 files changed, 19 insertions(+), 8 deletions(-)

jump to
M cmd/searchix-web/main.gocmd/searchix-web/main.go
@@ -55,7 +55,10 @@ if err != nil {
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) }
M searchix.gosearchix.go
@@ -38,7 +38,12 @@
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 @@ i++
} 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 {