force to set pdf service

This commit is contained in:
Ruidy 2024-02-25 00:17:49 +01:00
parent 6a25589751
commit a31a1f6350
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 16 additions and 6 deletions

View file

@ -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 {

View file

@ -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()
}