typecast, fix fmt

This commit is contained in:
Bernard Xie 2022-11-21 11:05:10 -08:00
parent 8b53a86345
commit 794df257a7
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
2 changed files with 3 additions and 2 deletions

2
go.mod
View file

@ -11,6 +11,7 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mazznoer/csscolorparser v0.1.3
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/playwright-community/playwright-go v0.2000.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/yuin/goldmark v1.5.2
@ -47,7 +48,6 @@ require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/playwright-community/playwright-go v0.2000.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect

View file

@ -8,6 +8,7 @@ import (
_ "embed"
"github.com/playwright-community/playwright-go"
"oss.terrastruct.com/d2/lib/xmain"
)
@ -79,7 +80,7 @@ func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, erro
return nil, fmt.Errorf("failed to generate png: %w\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", err)
}
pngString := fmt.Sprintf("%v", pngInterface)
pngString := pngInterface.(string)
if !strings.HasPrefix(pngString, pngPrefix) {
if len(pngString) > 50 {
pngString = pngString[0:50] + "..."