Skip to content

Commit 43e85bc

Browse files
committed
Update examples with json export.
1 parent 1c4d972 commit 43e85bc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

examples/hotp/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"log"
67

@@ -54,8 +55,11 @@ func main() {
5455
ku := h.KeyUri(aUsername, anIssuer)
5556

5657
// From here you can get the plain text uri.
57-
msg = "Exporting config for \"%s\" at \"%s\":\n\t- Plain URI --> %s\n\t- QR code image, base 64 encoded (" +
58-
"truncated to save space) --> %s...\n"
58+
msg = "Exporting config for \"%s\" at \"%s\":\n" +
59+
"\t- Plain URI --> %s\n" +
60+
"\t- QR code image, base 64 encoded (truncated to save space) --> %s...\n" +
61+
"\t- JSON --> %s\n"
5962
qr, _ := ku.QRCode()
60-
fmt.Printf(msg, aUsername, anIssuer, ku.String(), qr[0:200])
63+
jsonParams, _ := json.Marshal(ku)
64+
fmt.Printf(msg, aUsername, anIssuer, ku.String(), qr[0:200], jsonParams)
6165
}

examples/totp/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"log"
67

@@ -46,8 +47,11 @@ func main() {
4647
ku := t.KeyUri(aUsername, anIssuer)
4748

4849
// From here you can get the plain text uri.
49-
msg = "Exporting config for \"%s\" at \"%s\":\n\t- Plain URI --> %s\n\t- QR code image, base 64 encoded (" +
50-
"truncated to save space) --> %s...\n"
50+
msg = "Exporting config for \"%s\" at \"%s\":\n" +
51+
"\t- Plain URI --> %s\n" +
52+
"\t- QR code image, base 64 encoded (truncated to save space) --> %s...\n" +
53+
"\t- JSON --> %s\n"
5154
qr, _ := ku.QRCode()
52-
fmt.Printf(msg, aUsername, anIssuer, ku.String(), qr[0:200])
55+
jsonParams, _ := json.Marshal(ku)
56+
fmt.Printf(msg, aUsername, anIssuer, ku.String(), qr[0:200], jsonParams)
5357
}

0 commit comments

Comments
 (0)