fix: adjust some code structure to satisfy linter
This commit is contained in:
parent
7b30a04933
commit
4060ec09c4
7 changed files with 38 additions and 31 deletions
30
main.go
30
main.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -24,7 +24,7 @@ func main() {
|
|||
cli := cmd.CLI{}
|
||||
config, err := cli.Parse()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
handleGracefulShutdown()
|
||||
|
@ -38,15 +38,16 @@ func main() {
|
|||
ctx := downloader.NewContext(config.DataFile, config.DataURL)
|
||||
if !ctx.FileExists() {
|
||||
if downloadErr := ctx.Download(); downloadErr != nil {
|
||||
log.Fatal(downloadErr)
|
||||
panic(err)
|
||||
}
|
||||
log.Printf("saved file to %s\n", ctx.Filename)
|
||||
slog.Info("saved file", "path", ctx.Filename)
|
||||
}
|
||||
|
||||
cache := cache.NewCache(config.CacheTTL)
|
||||
db, err := database.NewDatabase(config)
|
||||
if err != nil {
|
||||
log.Fatal("database creation failed", err)
|
||||
slog.Error("database creation failed")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if config.EnableExporter {
|
||||
|
@ -66,23 +67,24 @@ func main() {
|
|||
}
|
||||
}
|
||||
}()
|
||||
log.Println("prometheus exporter refreshes metric data every", config.ExporterInterval)
|
||||
slog.Info("prometheus exporter refreshes metric data", "interval", config.ExporterInterval)
|
||||
|
||||
go func() {
|
||||
err = exporter.Start()
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
log.Println("prometheus exporter started at", config.ExporterAddress)
|
||||
slog.Info("prometheus exporter started", "address", config.ExporterAddress)
|
||||
}
|
||||
|
||||
log.Println("importing data from file", config.DataFile)
|
||||
slog.Info("importing data from file", "path", config.DataFile)
|
||||
err = csvimporter.ImportCSV(config.DataFile, db)
|
||||
if err != nil {
|
||||
log.Fatal("data Import from file failed", err)
|
||||
slog.Error("data import from file failed")
|
||||
panic(err)
|
||||
}
|
||||
log.Println("imported data from file successful")
|
||||
slog.Info("imported data from file successfully")
|
||||
|
||||
lh := apiv1.NewLocationHandler(cache, db)
|
||||
r.Mount("/api/v1", apiv1.NewRouter(lh))
|
||||
|
@ -93,9 +95,9 @@ func main() {
|
|||
ReadHeaderTimeout: config.ReadHeaderTimeout,
|
||||
}
|
||||
|
||||
log.Println("starting server at", server.Addr)
|
||||
slog.Info("starting server", "address", server.Addr)
|
||||
if err = server.ListenAndServe(); err != nil {
|
||||
log.Panic(err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +108,7 @@ func handleGracefulShutdown() {
|
|||
|
||||
go func() {
|
||||
sig := <-signals
|
||||
log.Printf("caught signal: %+v", sig)
|
||||
slog.Info("caught signal", "signal", sig)
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue