From a31a1f635079504c41c8ecd150c956a56b70df7c Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 25 Feb 2024 00:17:49 +0100 Subject: [PATCH] force to set pdf service --- internal/pdf/service.go | 16 +++++++++++----- main.go | 6 +++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/pdf/service.go b/internal/pdf/service.go index 09906c6..f8cfc8f 100644 --- a/internal/pdf/service.go +++ b/internal/pdf/service.go @@ -24,13 +24,19 @@ type PdfService struct { apiKey string } -func NewPdfService() *PdfService { +func NewPdfService() (*PdfService, error) { + pid := os.Getenv("HTMLDOCS_PROJECT_ID") + url := os.Getenv("HTMLDOCS_URL") + key := os.Getenv("HTMLDOCS_KEY") + if pid == "" || url == "" || key == "" { + return nil, errors.New("error building Pdf service. Verify your env variables") + } return &PdfService{ invoicePath: "index.html", - projectId: os.Getenv("HTMLDOCS_PROJECT_ID"), - url: os.Getenv("HTMLDOCS_URL"), - apiKey: os.Getenv("HTMLDOCS_KEY"), - } + projectId: pid, + url: url, + apiKey: key, + }, nil } func (ps PdfService) BuildInvoice(b *booking.Booking, hc *config.Host) error { diff --git a/main.go b/main.go index fa6698d..9c4bbe8 100644 --- a/main.go +++ b/main.go @@ -38,5 +38,9 @@ func main() { log.Fatalf("error migrating the database %s\n", err) } - server.New(&static, booking.NewService(db), pdf.NewPdfService(), config.NewHost()).Start() + ps, err := pdf.NewPdfService() + if err != nil { + log.Fatal(err) + } + server.New(&static, booking.NewService(db), ps, config.NewHost()).Start() }