Better error handling, many fixes all around
This commit is contained in:
21
main.go
21
main.go
@@ -1,16 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"gemini-grc/config"
|
||||
"gemini-grc/gemini"
|
||||
"gemini-grc/http"
|
||||
"gemini-grc/logging"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/rs/zerolog"
|
||||
zlog "github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -26,9 +26,10 @@ func main() {
|
||||
|
||||
func runApp() error {
|
||||
logging.LogInfo("Starting up. Press Ctrl+C to exit")
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
server := http.CreateServer("localhost:8899")
|
||||
db := gemini.ConnectToDB()
|
||||
|
||||
// !!! DANGER !!!
|
||||
@@ -44,7 +45,8 @@ func runApp() error {
|
||||
}(db)
|
||||
|
||||
gemini.LoadBlacklist()
|
||||
|
||||
// If there's an argument, assume it's a URL
|
||||
// to visit and ignore database state.
|
||||
if len(os.Args) > 1 {
|
||||
url := os.Args[1]
|
||||
go gemini.RunWorker(0, db, &url)
|
||||
@@ -52,7 +54,10 @@ func runApp() error {
|
||||
go gemini.SpawnWorkers(config.CONFIG.NumOfWorkers, db)
|
||||
}
|
||||
|
||||
<-sigs
|
||||
<-signals
|
||||
if err := server.Close(); err != nil {
|
||||
logging.LogError("GeminiError during server shutdown: %s", err)
|
||||
}
|
||||
logging.LogInfo("Received SIGINT or SIGTERM signal, exiting")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user