feat(templates): Fallback image
This commit is contained in:
parent
e10448f1e3
commit
d910a722df
@ -7,6 +7,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"image/png"
|
"image/png"
|
||||||
|
|
||||||
|
"git.odit.services/lfk/document-server/templates"
|
||||||
"github.com/boombuler/barcode"
|
"github.com/boombuler/barcode"
|
||||||
"github.com/boombuler/barcode/code128"
|
"github.com/boombuler/barcode/code128"
|
||||||
"github.com/boombuler/barcode/ean"
|
"github.com/boombuler/barcode/ean"
|
||||||
@ -79,10 +80,14 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
|
|||||||
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
|
return base64.StdEncoding.EncodeToString(buf.Bytes()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||||
|
return templates.GetImage("error"), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||||
return template.New("template").Funcs(template.FuncMap{
|
return template.New("template").Funcs(template.FuncMap{
|
||||||
"barcode": t.GenerateBarcode,
|
"barcode": t.GenerateBarcode,
|
||||||
"sponsorLogo": func(id int) string { return "a" },
|
"sponsorLogo": t.SelectSponsorImage,
|
||||||
}).Parse(templateString)
|
}).Parse(templateString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
templates/images/error.base64
Normal file
1
templates/images/error.base64
Normal file
File diff suppressed because one or more lines are too long
@ -20,6 +20,9 @@ var ContractTemplateDe string
|
|||||||
//go:embed images/sponsoringheader.base64
|
//go:embed images/sponsoringheader.base64
|
||||||
var ImageSponsoringHeaderBase64 string
|
var ImageSponsoringHeaderBase64 string
|
||||||
|
|
||||||
|
//go:embed images/error.base64
|
||||||
|
var ImageErrorBase64 string
|
||||||
|
|
||||||
func GetTemplate(locale, templateName string) (string, error) {
|
func GetTemplate(locale, templateName string) (string, error) {
|
||||||
switch templateName {
|
switch templateName {
|
||||||
case "card":
|
case "card":
|
||||||
@ -39,3 +42,12 @@ func GetTemplate(locale, templateName string) (string, error) {
|
|||||||
}
|
}
|
||||||
return "", fmt.Errorf("template not found with name %s and locale %s", templateName, locale)
|
return "", fmt.Errorf("template not found with name %s and locale %s", templateName, locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetImage(imageName string) string {
|
||||||
|
switch imageName {
|
||||||
|
case "sponsoringheader":
|
||||||
|
return ImageSponsoringHeaderBase64
|
||||||
|
default:
|
||||||
|
return ImageErrorBase64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user