Skip to content

Commit

Permalink
docs: add migrating from v1 example
Browse files Browse the repository at this point in the history
  • Loading branch information
yeqown committed Nov 30, 2021
1 parent 166a111 commit a1a245a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ following are some shots:

Of course, you can also code your own writer, just implement [Writer](./writer/README.md) interface.

### Migrating from v1

`go-qrcode.v2` is a major upgrade from v1, and it is not backward compatible. `v2` redesigned
the API, and it is more flexible and powerful. Features are split into different modules (according to functionality).

- github.com/yeqown/go-qrcode/v2 **_core_**
- github.com/yeqown/go-qrcode/writer/standard **_writer/imageFile_**
- github.com/yeqown/go-qrcode/writer/terminal **_writer/terminal_**

Check [example/migrating-from-v1](./example/migrating-from-v1/main.go) for more details.

### Links

* [QRCode Tourist](https://www.thonky.com/qr-code-tutorial/)
Expand Down
1 change: 1 addition & 0 deletions example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module example
go 1.17

require (
github.com/yeqown/go-qrcode v1.5.10
github.com/yeqown/go-qrcode/v2 v2.0.0-beta
github.com/yeqown/go-qrcode/writer/standard v1.0.0-beta
github.com/yeqown/go-qrcode/writer/terminal v1.0.0-beta
Expand Down
70 changes: 70 additions & 0 deletions example/migrating-from-v1/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
qrv2 "github.com/yeqown/go-qrcode/v2"
"github.com/yeqown/go-qrcode/writer/standard"

qrv1 "github.com/yeqown/go-qrcode"
)

func main() {
// draw a QRCode image with
// - "https://github.com/yeqown/go-qrcode" source text
// - circle shape
// - blue foreground color
// - white background color
// - 20 pixel block width
// - 20 pixel border width
// - The Highest error correction level

v1()

v2()
}

func v1() {
encodeConfig := &qrv1.Config{
EcLevel: qrv1.ErrorCorrectionHighest,
EncMode: qrv1.EncModeAuto,
}
qrc, err := qrv1.NewWithConfig("https://github.com/yeqown/go-qrcode", encodeConfig,
qrv1.WithCircleShape(),
qrv1.WithFgColorRGBHex("#0000ff"),
qrv1.WithBgColorRGBHex("#ffffff"),
qrv1.WithQRWidth(20),
qrv1.WithBorderWidth(20),
)
if err != nil {
panic(err)
}

err = qrc.Save("v1.jpeg")
if err != nil {
panic(err)
}
}

func v2() {
qrc, err := qrv2.NewWith("https://github.com/yeqown/go-qrcode",
qrv2.WithErrorCorrectionLevel(qrv2.ErrorCorrectionHighest),
)
if err != nil {
panic(err)
}

w, err := standard.New("v2.jpeg",
standard.WithCircleShape(),
standard.WithFgColorRGBHex("#0000ff"),
standard.WithBgColorRGBHex("#ffffff"),
standard.WithQRWidth(20),
standard.WithBorderWidth(20),
)
if err != nil {
panic(err)
}

err = qrc.Save(w)
if err != nil {
panic(err)
}
}

0 comments on commit a1a245a

Please sign in to comment.