mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
refactor: simplify main entry and improve logging
Refactors main.go to streamline context and logger initialization. Moves signal handling directly into main, sets up a base logger for early errors, and updates error handling to use structured logging. No functional changes to application logic.
This commit is contained in:
parent
ac94faedb0
commit
5d42a5aefe
2 changed files with 23 additions and 23 deletions
|
|
@ -25,18 +25,18 @@ func NewBookingAgentParser() *BookingAgentParser {
|
|||
|
||||
{
|
||||
"data": {
|
||||
"arrival_date": "YYYY-MM-DD",
|
||||
"booking_fees": "number as string",
|
||||
"booking_id": "string",
|
||||
"departure_date": "YYYY-MM-DD",
|
||||
"stay_length": int,
|
||||
"guest_email": "string",
|
||||
"guest_name": "string",
|
||||
"guest_number": int,
|
||||
"guest_phone": "string",
|
||||
"room_booked": "string",
|
||||
"standard_rate": "number as string",
|
||||
"special_requests": "string"
|
||||
"arrival_date": "YYYY-MM-DD",
|
||||
"booking_fees": "number as string",
|
||||
"booking_id": "string",
|
||||
"departure_date": "YYYY-MM-DD",
|
||||
"stay_length": int,
|
||||
"guest_email": "string",
|
||||
"guest_name": "string",
|
||||
"guest_number": int,
|
||||
"guest_phone": "string",
|
||||
"room_booked": "string",
|
||||
"standard_rate": "number as string",
|
||||
"special_requests": "string"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
22
main.go
22
main.go
|
|
@ -22,26 +22,26 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := run(ctx); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c context.Context) error {
|
||||
ctx, cancel := signal.NotifyContext(c, os.Interrupt)
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
defer cancel()
|
||||
|
||||
baseLogger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))
|
||||
|
||||
appConfig, err := config.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
baseLogger.Error("configuration error", slog.Any("error", err))
|
||||
}
|
||||
|
||||
appLogger := logger.New(appConfig.LogLevel)
|
||||
slog.SetDefault(appLogger)
|
||||
|
||||
if err := run(appConfig, appLogger); err != nil {
|
||||
appLogger.Error("server exited", slog.Any("error", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(appConfig *config.Config, appLogger *slog.Logger) error {
|
||||
// init sentry
|
||||
if err := sentry.Init(sentry.ClientOptions{
|
||||
Dsn: appConfig.SentryDsn,
|
||||
|
|
|
|||
Loading…
Reference in a new issue