diff --git a/README.md b/README.md index 011cf21..ef13da6 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/example/go.mod b/example/go.mod index 274c4fc..915b7c6 100644 --- a/example/go.mod +++ b/example/go.mod @@ -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 diff --git a/example/migrating-from-v1/main.go b/example/migrating-from-v1/main.go new file mode 100644 index 0000000..57de8ea --- /dev/null +++ b/example/migrating-from-v1/main.go @@ -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) + } +}