make format=txt display the textual QR code contents

This allows for easy comparison with QR codes extracted from PDFs:

pdfimages -png invoice.pdf invoice && \
  zbarimg --raw invoice*.png > code.txt
This commit is contained in:
Michael Stapelberg
2022-07-17 09:16:53 +02:00
parent 0fcc077935
commit 05d1f60c14
4 changed files with 7 additions and 2 deletions

View File

@@ -27,7 +27,6 @@ import (
"os" "os"
"strings" "strings"
"github.com/davecgh/go-spew/spew"
"github.com/mattn/go-isatty" "github.com/mattn/go-isatty"
"github.com/stapelberg/qrbill" "github.com/stapelberg/qrbill"
@@ -184,7 +183,7 @@ func logic() error {
case "txt": case "txt":
w.Header().Add("Content-Type", "text/plain; charset=utf-8") w.Header().Add("Content-Type", "text/plain; charset=utf-8")
spew.Fdump(w, qrch.Validate()) fmt.Fprintf(w, "%s", bill.EncodeToString())
case "html": case "html":
debugHTML(w, r, prefix, qrch) debugHTML(w, r, prefix, qrch)

View File

@@ -1,3 +1,4 @@
//go:build gokrazy
// +build gokrazy // +build gokrazy
// Copyright 2020 Google LLC // Copyright 2020 Google LLC

View File

@@ -263,6 +263,10 @@ type Bill struct {
qrcontents string qrcontents string
} }
func (b *Bill) EncodeToString() string {
return b.qrcontents
}
func (b *Bill) EncodeToSVG() ([]byte, error) { func (b *Bill) EncodeToSVG() ([]byte, error) {
var err error var err error
code, err := encoder.Encoder_encode(b.qrcontents, decoder.ErrorCorrectionLevel_M, qrEncodeHints()) code, err := encoder.Encoder_encode(b.qrcontents, decoder.ErrorCorrectionLevel_M, qrEncodeHints())

View File

@@ -1,5 +1,6 @@
// copied from https://github.com/dsymonds/goembed/ with pull requests applied // copied from https://github.com/dsymonds/goembed/ with pull requests applied
//go:build ignore
// +build ignore // +build ignore
// goembed - Embed data in Go source code // goembed - Embed data in Go source code