admin: Use gin-gonic as router
This commit is contained in:
parent
83468ad723
commit
8b3fbdb64a
32 changed files with 2785 additions and 1635 deletions
|
@ -1,9 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -198,12 +196,12 @@ func main() {
|
|||
os.MkdirAll(settings.SettingsDir, 0777)
|
||||
|
||||
// Initialize settings and load them
|
||||
var config *settings.Settings
|
||||
if !settings.ExistsSettings(path.Join(settings.SettingsDir, settings.SettingsFile)) {
|
||||
if err = api.ResetSettings(); err != nil {
|
||||
log.Fatal("Unable to initialize settings.json:", err)
|
||||
}
|
||||
} else {
|
||||
var config *settings.Settings
|
||||
if config, err = settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
|
||||
log.Fatal("Unable to read settings.json:", err)
|
||||
} else {
|
||||
|
@ -231,21 +229,13 @@ func main() {
|
|||
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))
|
||||
app := NewApp(config, baseURL, *bind)
|
||||
go app.Start()
|
||||
|
||||
// Wait shutdown signal
|
||||
<-interrupt
|
||||
|
||||
log.Print("The service is shutting down...")
|
||||
srv.Shutdown(context.Background())
|
||||
app.Stop()
|
||||
log.Println("done")
|
||||
}
|
||||
|
|
Reference in a new issue