qa: Use gin

This commit is contained in:
nemunaire 2022-11-06 16:36:31 +01:00
parent 9fd5564410
commit abdf146fea
13 changed files with 596 additions and 378 deletions

View file

@ -1,9 +1,8 @@
package main
import (
"context"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"net/url"
@ -80,8 +79,20 @@ func main() {
// Sanitize options
var err error
log.Println("Checking paths...")
if StaticDir, err = filepath.Abs(StaticDir); err != nil {
log.Fatal(err)
if StaticDir != "" {
if sDir, err := filepath.Abs(StaticDir); err != nil {
log.Fatal(err)
} else {
log.Println("Serving pages from", sDir)
staticFS = http.Dir(sDir)
}
} else {
sub, err := fs.Sub(assets, "static")
if err != nil {
log.Fatal("Unable to cd to static/ directory:", err)
}
log.Println("Serving pages from memory.")
staticFS = http.FS(sub)
}
if BaseURL != "/" {
BaseURL = path.Clean(BaseURL)
@ -101,25 +112,17 @@ func main() {
}
defer fic.DBClose()
a := NewApp(BaseURL)
go a.Start(*bind)
// Prepare graceful shutdown
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
srv := &http.Server{
Addr: *bind,
Handler: StripPrefix(BaseURL, api.Router()),
}
// Serve content
go func() {
log.Fatal(srv.ListenAndServe())
}()
log.Println(fmt.Sprintf("Ready, listening on %s", *bind))
// Wait shutdown signal
<-interrupt
log.Print("The service is shutting down...")
srv.Shutdown(context.Background())
a.Stop()
log.Println("done")
}