embed html template
6
assets/assets.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package assets
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed assets
|
||||
var Static embed.FS
|
||||
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
|
|
@ -6,6 +6,8 @@ import (
|
|||
"os"
|
||||
"text/template"
|
||||
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/rjNemo/rentease/assets"
|
||||
"github.com/rjNemo/rentease/internal/service/booking"
|
||||
)
|
||||
|
||||
|
|
@ -16,9 +18,10 @@ func NewPdfClient() (*HtmlPdfClient, error) {
|
|||
}
|
||||
|
||||
func (pc *HtmlPdfClient) BuildInvoice(data booking.Invoice) (string, error) {
|
||||
tmpl, err := template.ParseFiles("assets/html/invoice.html")
|
||||
log.Info("building invoice")
|
||||
tmpl, err := template.ParseFS(assets.Static, "assets/html/invoice.html")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error parsing template: %v", err)
|
||||
return "", fmt.Errorf("error parsing template: %v", err)
|
||||
}
|
||||
|
||||
// Create a buffer to hold the rendered HTML.
|
||||
|
|
@ -32,6 +35,7 @@ func (pc *HtmlPdfClient) BuildInvoice(data booking.Invoice) (string, error) {
|
|||
return "", fmt.Errorf("error writing HTML file: %v", err)
|
||||
}
|
||||
|
||||
log.Info("building invoice")
|
||||
return outputPath, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,5 +101,6 @@ func (bs Service) Cancel(id int) {
|
|||
}
|
||||
|
||||
func (bs Service) BuildInvoice(b *Booking, hc *config.Host) (string, error) {
|
||||
log.Println("Build invoice")
|
||||
return bs.pdf.BuildInvoice(b.ToInvoice(hc))
|
||||
}
|
||||
|
|
|
|||
7
main.go
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -11,6 +10,7 @@ import (
|
|||
|
||||
"github.com/getsentry/sentry-go"
|
||||
|
||||
"github.com/rjNemo/rentease/assets"
|
||||
"github.com/rjNemo/rentease/internal/config"
|
||||
"github.com/rjNemo/rentease/internal/driver/calendar"
|
||||
"github.com/rjNemo/rentease/internal/driver/database"
|
||||
|
|
@ -22,9 +22,6 @@ import (
|
|||
"github.com/rjNemo/rentease/internal/service/booking"
|
||||
)
|
||||
|
||||
//go:embed assets
|
||||
var static embed.FS
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
@ -102,7 +99,7 @@ func run(c context.Context, getEnv func(string) string) error {
|
|||
as,
|
||||
config.NewHost(), // TODO: move to the database at some point
|
||||
server.WithPort(port),
|
||||
server.WithFileSystem(static),
|
||||
server.WithFileSystem(assets.Static),
|
||||
server.WithDebug(strings.ToLower(getEnv("DEBUG")) == "true"),
|
||||
server.WithSecretKey(getEnv("SECRET_KEY")),
|
||||
server.WithOrigins(origins),
|
||||
|
|
|
|||