feat: support png output type

This commit is contained in:
vicanso 2022-06-24 20:25:31 +08:00
parent 1c60bc9380
commit 7894d99953
4 changed files with 32 additions and 5 deletions

13
main.go
View file

@ -3,6 +3,7 @@ package main
import (
"bytes"
"embed"
"encoding/base64"
"fmt"
"time"
@ -50,10 +51,20 @@ func main() {
return nil
})
e.POST("/", func(c *elton.Context) error {
buf, err := charts.RenderEChartsToSVG(string(c.RequestBody))
outputType := c.QueryParam("outputType")
fn := charts.RenderEChartsToSVG
isPNG := false
if outputType == "png" {
isPNG = true
fn = charts.RenderEChartsToPNG
}
buf, err := fn(string(c.RequestBody))
if err != nil {
return err
}
if isPNG {
buf = []byte(base64.StdEncoding.EncodeToString(buf))
}
c.BodyBuffer = bytes.NewBuffer(buf)
return nil
})