Reuse single instance of chrome

This commit is contained in:
Marcus Noble 2021-06-20 11:55:51 +01:00
parent 48599bac5f
commit 22e1d72e01

View File

@ -23,7 +23,11 @@ import (
var content embed.FS var content embed.FS
var chrome *svg2png.Chrome
func main() { func main() {
chrome = svg2png.NewChrome().SetHeight(600).SetWith(1200).SetTimeout(10 * time.Second)
app := fiber.New() app := fiber.New()
app.Use(compress.New()) app.Use(compress.New())
app.Use(cors.New()) app.Use(cors.New())
@ -91,7 +95,6 @@ func generateImage(vars map[string]string) ([]byte, error) {
imageFile, err := os.CreateTemp(os.TempDir(), "img-*.png") imageFile, err := os.CreateTemp(os.TempDir(), "img-*.png")
chrome := svg2png.NewChrome().SetHeight(600).SetWith(1200).SetTimeout(10 * time.Second)
if err := chrome.Screenshoot(fmt.Sprintf("file://%s", file.Name()), imageFile.Name()); err != nil { if err := chrome.Screenshoot(fmt.Sprintf("file://%s", file.Name()), imageFile.Name()); err != nil {
return nil, err return nil, err
} }