Skip to content

Commit

Permalink
Release 24.6 (#60)
Browse files Browse the repository at this point in the history
* Version of SDK updated.

Package updated

* Update examples

* Use system staticcheck

---------

Co-authored-by: Ivan Kamkin <[email protected]>
  • Loading branch information
Denis-Averin and Ivan Kamkin authored Jun 27, 2024
1 parent bb7a23f commit f6811c9
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 96 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
185 changes: 98 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 )
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion barcode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion barcode/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion examples/generate/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
go install honnef.co/go/tools/cmd/[email protected]
8 changes: 8 additions & 0 deletions scripts/insert-examples.bash
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 46 additions & 0 deletions scripts/insert-examples.go
Original file line number Diff line number Diff line change
@@ -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.")
}
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -euo pipefail

go vet -v ./...
"$(go env GOPATH)/bin/staticcheck" ./...
staticcheck ./...

0 comments on commit f6811c9

Please sign in to comment.