improve startup with deferred scan
This commit is contained in:
+12
-7
@@ -66,13 +66,6 @@ func (cli *CLI) RunE(cmd *cobra.Command, rootDirs []string) error {
|
||||
return errors.New("at least one extension required")
|
||||
}
|
||||
|
||||
files, err := cli.db.MultiScan(rootDirs...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cli.db.Import(files.WithExtensions(extensions...))
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.Use(middlewares.NewCorsOrigin("*").Middleware)
|
||||
router.Use(mux.CORSMethodMiddleware(router))
|
||||
@@ -91,11 +84,23 @@ func (cli *CLI) RunE(cmd *cobra.Command, rootDirs []string) error {
|
||||
srv.ConfigureStaticAssets(router)
|
||||
|
||||
errch := make(chan error)
|
||||
|
||||
// Start HTTP server
|
||||
go func() {
|
||||
addr := net.JoinHostPort(host, strconv.Itoa(port))
|
||||
errch <- http.ListenAndServe(addr, router)
|
||||
}()
|
||||
|
||||
// Initial scan of root directories
|
||||
go func() {
|
||||
files, err := cli.db.MultiScan(rootDirs...)
|
||||
if err != nil {
|
||||
errch <- err
|
||||
}
|
||||
|
||||
cli.db.Import(files.WithExtensions(extensions...))
|
||||
}()
|
||||
|
||||
cli.log.Info().Int("port", port).Msg("Listening for HTTP connections")
|
||||
return <-errch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user