Aspose.BarCode Cloud SDK for Go

- API version: 4.0
- SDK version: 4.2606.0
SDK and API Version Compatibility:
- SDK Version 4.2501.0 and Later: Starting from SDK version 25.1, all subsequent versions are compatible with API Version v4.0.
- SDK Version 1.2412.0 and Earlier: These versions are compatible with API Version v3.0.
Demo applications
Aspose.BarCode for Cloud is a REST API for Linear, 2D and postal barcode generation and recognition in the cloud. API recognizes and generates barcode images in a variety of formats. Barcode REST API allows to specify barcode image attributes like image width, height, border style and output image format in order to customize the generation process. Developers can also specify the barcode type and text attributes such as text location and font styles in order to suit the application requirements.
This repository contains Aspose.BarCode Cloud SDK for Go source code. This SDK allows you to work with Aspose.BarCode for Cloud REST APIs in your Go applications quickly and easily.
To use these SDKs, you will need Client Id and Client Secret which can be looked up at Aspose Cloud Dashboard (free registration in Aspose Cloud is required for this).
AI Agent Skills
This repository includes an AI-agent skill in skills/generate-and-scan-barcode-go/SKILL.md. Point your coding agent to it when working with this SDK so it follows the repo workflow and SDK-specific API patterns.
Prerequisites
To use Aspose.BarCode Cloud SDK for Go you need to register an account with Aspose Cloud and lookup/create Client Secret and SID at Cloud Dashboard. There is a free quota available. For more details, see Aspose Cloud Pricing.
Installation
Using Go Modules (recommended)
-
Go to existing module directory, or create a new module (see https://blog.golang.org/using-go-modules)
-
Run go get command
go get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4@v4.2606.0
Sample usage
Generate an image with barcode
The examples below show how you can generate QR barcode and save it into a local file using barcode:
package main
import (
"context"
"fmt"
"os"
"github.com/antihax/optional"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/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.GenerateAPIGenerateOpts{
BarcodeImageParams: optional.NewInterface(barcode.BarcodeImageParams{
TextLocation: barcode.CodeLocationNone,
}),
QrParams: optional.NewInterface(barcode.QrParams{
QrEncodeMode: barcode.QREncodeModeAuto,
QrErrorLevel: barcode.QRErrorLevelLevelM,
QrVersion: barcode.QRVersionAuto,
QrAspectRatio: 0.75,
}),
}
data, _, err := client.GenerateAPI.Generate(authCtx,
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 scan barcode text and type on the image using barcode:
package main
import (
"context"
"fmt"
"os"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/barcode"
"github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/v4/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"
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()))
recognized, _, err := client.ScanAPI.ScanMultipart(
authCtx,
imageFile)
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
- github.com/antihax/optional
- github.com/google/uuid
- golang.org/x/oauth2
Licensing
All Aspose.BarCode for Cloud SDKs, helper scripts and templates are licensed under MIT License.
Resources
Documentation for API Endpoints
All URIs are relative to https://api.aspose.cloud/v4.0
| Class |
Method |
HTTP request |
Description |
| GenerateAPI |
Generate |
Get /barcode/generate/{barcodeType} |
Generate a barcode using a GET request with parameters in the route and query string. |
| GenerateAPI |
GenerateBody |
Post /barcode/generate-body |
Generate a barcode using a POST request with parameters in the request body in JSON or XML format. |
| GenerateAPI |
GenerateMultipart |
Post /barcode/generate-multipart |
Generate a barcode using a POST request with parameters in a multipart form. |
| RecognizeAPI |
Recognize |
Get /barcode/recognize |
Recognize a barcode from a file on an Internet server using a GET request with a query string parameter. For recognizing files from your hard drive, use `recognize-body` or `recognize-multipart` endpoints instead. |
| RecognizeAPI |
RecognizeBase64 |
Post /barcode/recognize-body |
Recognize a barcode from a file in the request body using a POST request with JSON or XML body parameters. |
| RecognizeAPI |
RecognizeMultipart |
Post /barcode/recognize-multipart |
Recognize a barcode from a file in the request body using a POST request with multipart form parameters. |
| ScanAPI |
Scan |
Get /barcode/scan |
Scan a barcode from a file on an Internet server using a GET request with a query string parameter. For scanning files from your hard drive, use `scan-body` or `scan-multipart` endpoints instead. |
| ScanAPI |
ScanBase64 |
Post /barcode/scan-body |
Scan a barcode from a file in the request body using a POST request with a JSON or XML body parameter. |
| ScanAPI |
ScanMultipart |
Post /barcode/scan-multipart |
Scan a barcode from a file in the request body using a POST request with a multipart form parameter. |
Documentation For Models