about summary refs log tree commit diff stats
path: root/internal/server
diff options
context:
space:
mode:
authorAlan Pearce2024-05-13 21:50:14 +0200
committerAlan Pearce2024-05-13 22:25:46 +0200
commit6b40e0c0fa90f11be14a93f1d6275779fd645cac (patch)
tree0df5bea87242450829ca441d235c077a0e09a149 /internal/server
parent2722f24af87f437ed9fcb8cc743ad1784141fd3a (diff)
downloadsearchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.lz
searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.tar.zst
searchix-6b40e0c0fa90f11be14a93f1d6275779fd645cac.zip
refactor: combine import and web server into one binary
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/mux.go17
-rw-r--r--internal/server/server.go5
2 files changed, 10 insertions, 12 deletions
diff --git a/internal/server/mux.go b/internal/server/mux.go
index 9d3b29a..582d154 100644
--- a/internal/server/mux.go
+++ b/internal/server/mux.go
@@ -16,8 +16,8 @@ import (
 
 	"searchix/frontend"
 	"searchix/internal/config"
+	search "searchix/internal/index"
 	"searchix/internal/options"
-	"searchix/internal/search"
 
 	"github.com/blevesearch/bleve/v2"
 	"github.com/getsentry/sentry-go"
@@ -63,15 +63,12 @@ func applyDevModeOverrides(config *config.Config) {
 	)
 }
 
-func NewMux(config *config.Config, liveReload bool) (*http.ServeMux, error) {
-	slog.Debug("loading index")
-	index, err := search.Open(config.DataPath)
-	slog.Debug("loaded index")
-	if err != nil {
-		log.Fatalf("could not open search index, error: %#v", err)
-	}
-
-	err = sentry.Init(sentry.ClientOptions{
+func NewMux(
+	config *config.Config,
+	index *search.ReadIndex,
+	liveReload bool,
+) (*http.ServeMux, error) {
+	err := sentry.Init(sentry.ClientOptions{
 		EnableTracing:    true,
 		TracesSampleRate: 1.0,
 		Dsn:              config.Web.SentryDSN,
diff --git a/internal/server/server.go b/internal/server/server.go
index 77163d3..bb0a6ad 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -7,6 +7,7 @@ import (
 	"net"
 	"net/http"
 	"searchix/internal/config"
+	"searchix/internal/index"
 	"time"
 
 	"github.com/pkg/errors"
@@ -16,8 +17,8 @@ type Server struct {
 	*http.Server
 }
 
-func New(conf *config.Config, liveReload bool) (*Server, error) {
-	mux, err := NewMux(conf, liveReload)
+func New(conf *config.Config, index *index.ReadIndex, liveReload bool) (*Server, error) {
+	mux, err := NewMux(conf, index, liveReload)
 	if err != nil {
 		return nil, err
 	}