web/searchix.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package web import ( "time" "go.alanpearce.eu/searchix/internal/config" "go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/searchix/internal/server" "go.alanpearce.eu/x/log" "github.com/getsentry/sentry-go" "gitlab.com/tozd/go/errors" ) type Server struct { sv *server.Server cfg *config.Config log *log.Logger sentryHub *sentry.Hub readIndex *index.ReadIndex } func New(cfg *config.Config, log *log.Logger, read *index.ReadIndex) (*Server, errors.E) { err := sentry.Init(sentry.ClientOptions{ EnableTracing: true, TracesSampleRate: 1.0, Dsn: cfg.Web.SentryDSN, Environment: cfg.Web.Environment, }) if err != nil { log.Warn("could not initialise sentry", "error", err) } return &Server{ cfg: cfg, log: log, sentryHub: sentry.CurrentHub(), readIndex: read, }, nil } func (s *Server) Start(liveReload bool) errors.E { var err errors.E s.sv, err = server.New(s.cfg, s.readIndex, s.log.Named("server"), liveReload) if err != nil { return errors.Wrap(err, "error setting up server") } err = s.sv.Start() if err != nil { return errors.Wrap(err, "error starting server") } return nil } func (s *Server) Stop() { <-s.sv.Stop() s.sentryHub.Flush(2 * time.Second) } |