From f6811c9e6dd3f9d92402552f730ab0333f3de0d8 Mon Sep 17 00:00:00 2001 From: Denis Averin <59285247+Denis-Averin@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:36:01 +0500 Subject: [PATCH] Release 24.6 (#60) * Version of SDK updated. Package updated * Update examples * Use system staticcheck --------- Co-authored-by: Ivan Kamkin <234-Ivan.Kamkin@users.noreply.git.saltov.dynabic.com> --- Makefile | 6 +- README.md | 185 +++++++++++++----------- barcode/client.go | 2 +- barcode/configuration.go | 2 +- examples/generate/example.go | 2 +- examples/{recognize => scan}/example.go | 0 go.mod | 2 +- go.sum | 4 +- scripts/init.sh | 1 - scripts/insert-examples.bash | 8 + scripts/insert-examples.go | 46 ++++++ scripts/lint.sh | 2 +- 12 files changed, 164 insertions(+), 96 deletions(-) rename examples/{recognize => scan}/example.go (100%) create mode 100755 scripts/insert-examples.bash create mode 100644 scripts/insert-examples.go diff --git a/Makefile b/Makefile index 09c6a3a..bd3ee1e 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,11 @@ update: update_packages clean-gomod release: format lint update_packages clean-gomod build test .PHONY: after-gen -after-gen: init format clean-gomod +after-gen: init format insert-examples clean-gomod + +.PHONY: insert-examples +insert-examples: + ./scripts/insert-examples.bash .PHONY: ci ci: build test diff --git a/README.md b/README.md index ba2ea51..ce99e26 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/aspose-barcode-cloud/aspose-barcode-cloud-go?label=module&sort=semver)](https://pkg.go.dev/github.com/aspose-barcode-cloud/aspose-barcode-cloud-go) - API version: 3.0 -- SDK version: 1.2405.0 +- SDK version: 1.2406.0 ## Demo applications @@ -33,7 +33,7 @@ To use Aspose.BarCode Cloud SDK for Go you need to register an account with [Asp 1. Run `go get` command ```shell script - go get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go@v1.2405.0 + go get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go@v1.2406.0 ``` ### Using GOPATH (for Go < 1.11 ) @@ -54,108 +54,119 @@ The examples below show how you can generate QR barcode and save it into a local package main import ( - "context" - "fmt" - "github.com/antihax/optional" - "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode" - "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode/jwt" - "os" + "context" + "fmt" + "os" + + "github.com/antihax/optional" + + "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode" + "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode/jwt" ) func main() { - jwtConf := jwt.NewConfig( - "Client Id from https://dashboard.aspose.cloud/applications", - "Client Secret from https://dashboard.aspose.cloud/applications", - ) - fileName := "testdata/generated.png" - - authCtx := context.WithValue(context.Background(), - barcode.ContextJWT, - jwtConf.TokenSource(context.Background())) - - client := barcode.NewAPIClient(barcode.NewConfiguration()) - - opts := &barcode.BarcodeApiGetBarcodeGenerateOpts{ - TextLocation: optional.NewString("None"), - } - - data, _, err := client.BarcodeApi.GetBarcodeGenerate(authCtx, - string(barcode.EncodeBarcodeTypeQR), - "Go SDK example", - opts) - if err != nil { - panic(err) - } - - out, err := os.Create(fileName) - if err != nil { - panic(err) - } - defer out.Close() - - written, err := out.Write(data) - if err != nil { - panic(err) - } - - fmt.Printf("Written %d bytes to file %s\n", written, fileName) + jwtConf := jwt.NewConfig( + "Client Id from https://dashboard.aspose.cloud/applications", + "Client Secret from https://dashboard.aspose.cloud/applications", + ) + fileName := "testdata/generated.png" + + authCtx := context.WithValue(context.Background(), + barcode.ContextJWT, + jwtConf.TokenSource(context.Background())) + + client := barcode.NewAPIClient(barcode.NewConfiguration()) + + opts := &barcode.BarcodeApiGetBarcodeGenerateOpts{ + TextLocation: optional.NewString(string(barcode.CodeLocationNone)), + } + + data, _, err := client.BarcodeApi.GetBarcodeGenerate(authCtx, + string(barcode.EncodeBarcodeTypeQR), + "Go SDK example", + opts) + if err != nil { + panic(err) + } + + out, err := os.Create(fileName) + if err != nil { + panic(err) + } + defer func(out *os.File) { + _ = out.Close() + }(out) + + written, err := out.Write(data) + if err != nil { + panic(err) + } + + fmt.Printf("Written %d bytes to file %s\n", written, fileName) } + ``` ### Recognize a barcode on image -The examples below show how you can recognize barcode text and type on the image using **barcode**: +The examples below show how you can scan barcode text and type on the image using **barcode**: ```go package main import ( - "context" - "fmt" - "github.com/antihax/optional" - "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode" - "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode/jwt" - "os" + "context" + "fmt" + "os" + + "github.com/antihax/optional" + "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode" + "github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode/jwt" ) func main() { - jwtConf := jwt.NewConfig( - "Client Id from https://dashboard.aspose.cloud/applications", - "Client Secret from https://dashboard.aspose.cloud/applications", - ) - fileName := "testdata/pdf417Sample.png" - - file, err := os.Open(fileName) - if err != nil { - panic(err) - } - defer file.Close() - - client := barcode.NewAPIClient(barcode.NewConfiguration()) - authCtx := context.WithValue(context.Background(), - barcode.ContextJWT, - jwtConf.TokenSource(context.Background())) - - optionals := barcode.BarcodeApiPostBarcodeRecognizeFromUrlOrContentOpts{ - Preset: optional.NewString(string(barcode.PresetTypeHighPerformance)), - Image: optional.NewInterface(file), - } - - recognized, _, err := client.BarcodeApi.PostBarcodeRecognizeFromUrlOrContent( - authCtx, - &optionals) - if err != nil { - panic(err) - } - - if len(recognized.Barcodes) == 0 { - fmt.Printf("No barcodes in %s", fileName) - } - - for i, oneBarcode := range recognized.Barcodes { - fmt.Printf("Recognized #%d: %s %s", i+1, oneBarcode.Type, oneBarcode.BarcodeValue) - } + jwtConf := jwt.NewConfig( + "Client Id from https://dashboard.aspose.cloud/applications", + "Client Secret from https://dashboard.aspose.cloud/applications", + ) + fileName := "testdata/generated.png" + + imageFile, err := os.Open(fileName) + if err != nil { + panic(err) + } + defer func(file *os.File) { + _ = file.Close() + }(imageFile) + + client := barcode.NewAPIClient(barcode.NewConfiguration()) + authCtx := context.WithValue(context.Background(), + barcode.ContextJWT, + jwtConf.TokenSource(context.Background())) + + optionals := barcode.BarcodeApiScanBarcodeOpts{ + DecodeTypes: optional.NewInterface([]barcode.DecodeBarcodeType{ + barcode.DecodeBarcodeTypeQR, + }), + } + + recognized, _, err := client.BarcodeApi.ScanBarcode( + authCtx, + imageFile, + &optionals) + if err != nil { + panic(err) + } + + if len(recognized.Barcodes) == 0 { + fmt.Printf("No barcodes in %s", fileName) + } + + for i, oneBarcode := range recognized.Barcodes { + fmt.Printf("Recognized #%d: %s %s", i+1, oneBarcode.Type, oneBarcode.BarcodeValue) + } } + ``` ## Dependencies diff --git a/barcode/client.go b/barcode/client.go index d0b66b5..24f21ca 100644 --- a/barcode/client.go +++ b/barcode/client.go @@ -21,7 +21,7 @@ import ( ) const ( - PACKAGE_VERSION = "1.2405.0" + PACKAGE_VERSION = "1.2406.0" PACKAGE_NAME = "go sdk" X_ASPOSE_CLIENT = "x-aspose-client" X_ASPOSE_CLIENT_VERSION = "x-aspose-client-version" diff --git a/barcode/configuration.go b/barcode/configuration.go index bb4fe2d..d789637 100644 --- a/barcode/configuration.go +++ b/barcode/configuration.go @@ -54,7 +54,7 @@ func NewConfiguration() *Configuration { cfg := &Configuration{ BasePath: "https://api.aspose.cloud/v3.0", DefaultHeader: make(map[string]string), - UserAgent: "Aspose-Barcode-SDK/1.2405.0/go", + UserAgent: "Aspose-Barcode-SDK/1.2406.0/go", } return cfg } diff --git a/examples/generate/example.go b/examples/generate/example.go index d869a6c..dfc955d 100644 --- a/examples/generate/example.go +++ b/examples/generate/example.go @@ -16,7 +16,7 @@ func main() { "Client Id from https://dashboard.aspose.cloud/applications", "Client Secret from https://dashboard.aspose.cloud/applications", ) - fileName := "../../testdata/generated.png" + fileName := "testdata/generated.png" authCtx := context.WithValue(context.Background(), barcode.ContextJWT, diff --git a/examples/recognize/example.go b/examples/scan/example.go similarity index 100% rename from examples/recognize/example.go rename to examples/scan/example.go diff --git a/go.mod b/go.mod index c71b498..63009b3 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/antihax/optional v1.0.0 github.com/google/uuid v1.6.0 github.com/stretchr/testify v1.9.0 - golang.org/x/oauth2 v0.20.0 + golang.org/x/oauth2 v0.21.0 ) require ( diff --git a/go.sum b/go.sum index 0656c64..26ddcd6 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= -golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/scripts/init.sh b/scripts/init.sh index 6787054..038dc20 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -4,4 +4,3 @@ set -euo pipefail go get -v -t -d ./... # Versions compatible with Go 1.17 go install golang.org/x/tools/cmd/goimports@v0.16.0 -go install honnef.co/go/tools/cmd/staticcheck@v0.3.3 diff --git a/scripts/insert-examples.bash b/scripts/insert-examples.bash new file mode 100755 index 0000000..6c0eece --- /dev/null +++ b/scripts/insert-examples.bash @@ -0,0 +1,8 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +go run "${SCRIPT_DIR}/insert-examples.go" + +rm "README.template" diff --git a/scripts/insert-examples.go b/scripts/insert-examples.go new file mode 100644 index 0000000..10acf4f --- /dev/null +++ b/scripts/insert-examples.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "os" + "regexp" +) + +func main() { + templateContent, err := os.ReadFile("README.template") + if err != nil { + fmt.Println("Error reading README.template file:", err) + panic(err) + } + + // Replace %insert path/to/file.go% with the content of the file + re := regexp.MustCompile(`%insert ([^%]+)%`) + + // Replace the placeholders with the file contents + result := re.ReplaceAllFunc(templateContent, func(match []byte) []byte { + // Extract the file path from the placeholder + matches := re.FindSubmatch(match) + if len(matches) < 2 { + return match + } + filePath := string(matches[1]) + + // Read the content of the file to be inserted + fileContent, err := os.ReadFile(filePath) + if err != nil { + fmt.Printf("Error reading file %s: %v\n", filePath, err) + panic(err) + } + + return fileContent + }) + + // Write the result to a new file or overwrite the existing file + err = os.WriteFile("README.md", result, 0644) + if err != nil { + fmt.Println("Error writing README.md file:", err) + panic(err) + } + + fmt.Println("README.md file created successfully.") +} diff --git a/scripts/lint.sh b/scripts/lint.sh index 43b42f0..ac40ddb 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -2,4 +2,4 @@ set -euo pipefail go vet -v ./... -"$(go env GOPATH)/bin/staticcheck" ./... +staticcheck ./...