delphi.market/server/router/pages/components/qr.templ

28 lines
530 B
Plaintext

package components
import (
"encoding/base64"
"github.com/skip2/go-qrcode"
)
templ Qr(value string, href string) {
if href != "" {
<a
class="mx-auto no-link"
href={ templ.SafeURL(href) }
>
<img src={ "data:image/jpeg;base64," + qrEncode(value) }/>
</a>
} else {
<img src={ "data:image/jpeg;base64," + qrEncode(value) }/>
}
}
func qrEncode(value string) string {
png, err := qrcode.Encode(value, qrcode.Medium, 256)
if err != nil {
return ""
}
return base64.StdEncoding.EncodeToString([]byte(png))
}