1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Marcus Noble e392e7ba8b Increased cache time 2021-06-20 11:58:07 +01:00
Marcus Noble 22e1d72e01 Reuse single instance of chrome 2021-06-20 11:55:51 +01:00
1 changed files with 6 additions and 4 deletions

10
main.go
View File

@ -23,14 +23,17 @@ import (
var content embed.FS
var chrome *svg2png.Chrome
func main() {
chrome = svg2png.NewChrome().SetHeight(600).SetWith(1200).SetTimeout(10 * time.Second)
ch := cache.New(24*time.Hour, 48*time.Hour)
app := fiber.New()
app.Use(compress.New())
app.Use(cors.New())
app.Use(logger.New())
ch := cache.New(6*time.Hour, 24*time.Hour)
app.Get("/", func(c *fiber.Ctx) error {
c.Type("html", "UTF8")
body, _ := content.ReadFile("index.html")
@ -60,7 +63,7 @@ func main() {
fmt.Println(err)
return c.SendStatus(500)
}
ch.Set(key, png, 0)
ch.Set(key, png, cache.DefaultExpiration)
}
c.Type("png")
@ -91,7 +94,6 @@ func generateImage(vars map[string]string) ([]byte, error) {
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 {
return nil, err
}