implement scan and index queue

This commit is contained in:
ston1th 2022-10-06 18:42:10 +02:00
commit e0314dcf56
4 changed files with 81 additions and 33 deletions

View file

@ -39,21 +39,27 @@ type HTTPServer struct {
JWT *jwt.JWT
Scanner *scan.Scanner
FS *fs.Filesystem
SQ *ScanQueue
Log logr.Logger
plain logr.Logger
cancel func()
templ map[string]*template.Template
res map[string][]byte
}
func NewHTTPServer(log logr.Logger, cfg *core.Config, l net.Listener, s *scan.Scanner) (srv *HTTPServer) {
ctx, cancel := context.WithCancel(context.Background())
srv = &HTTPServer{
Config: cfg,
listener: l,
Scanner: s,
Log: log.WithName("server"),
plain: log,
cancel: cancel,
}
srv.SQ = NewScanQueue(ctx, srv, 100)
srv.loadTemplates()
srv.srv = &http.Server{}
return
@ -88,6 +94,7 @@ func (s *HTTPServer) Start() (err error) {
} else {
s.srv.Handler = s.handler
}
go s.SQ.Scan()
go func() {
err = s.srv.Serve(s.listener)
if err != nil && err != http.ErrServerClosed {
@ -98,6 +105,7 @@ func (s *HTTPServer) Start() (err error) {
}
func (s *HTTPServer) Stop() error {
s.cancel()
s.DB.Close()
s.JWT.Stop()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)