README ¶
Aspose.BarCode Cloud SDK for Go
- API version: 3.0
- SDK version: 1.2412.0
Demo applications
Scan QR | Generate Barcode | Recognize Barcode |
---|---|---|
Generate Wi-Fi QR | Embed Barcode | Scan Barcode |
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).
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
commandgo get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go@v1.2412.0
Using GOPATH (for Go < 1.11 )
-
Run
go get
command outside module directorygo get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go/barcode
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/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(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 scan barcode text and type on the image using barcode:
package main
import (
"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"
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
- 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/v3.0
Class | Method | HTTP request | Description |
---|---|---|---|
BarcodeApi | GetBarcodeGenerate | Get /barcode/generate | Generate barcode. |
BarcodeApi | GetBarcodeRecognize | Get /barcode/{name}/recognize | Recognize barcode from a file on server. |
BarcodeApi | PostBarcodeRecognizeFromUrlOrContent | Post /barcode/recognize | Recognize barcode from an url or from request body. Request body can contain raw data bytes of the image with content-type "application/octet-stream". An image can also be passed as a form field. |
BarcodeApi | PostGenerateMultiple | Post /barcode/generateMultiple | Generate multiple barcodes and return in response stream |
BarcodeApi | PutBarcodeGenerateFile | Put /barcode/{name}/generate | Generate barcode and save on server (from query params or from file with json or xml content) |
BarcodeApi | PutBarcodeRecognizeFromBody | Put /barcode/{name}/recognize | Recognition of a barcode from file on server with parameters in body. |
BarcodeApi | PutGenerateMultiple | Put /barcode/{name}/generateMultiple | Generate image with multiple barcodes and put new file on server |
BarcodeApi | ScanBarcode | Post /barcode/scan | Quickly scan a barcode from an image. |
FileApi | CopyFile | Put /barcode/storage/file/copy/{srcPath} | Copy file |
FileApi | DeleteFile | Delete /barcode/storage/file/{path} | Delete file |
FileApi | DownloadFile | Get /barcode/storage/file/{path} | Download file |
FileApi | MoveFile | Put /barcode/storage/file/move/{srcPath} | Move file |
FileApi | UploadFile | Put /barcode/storage/file/{path} | Upload file |
FolderApi | CopyFolder | Put /barcode/storage/folder/copy/{srcPath} | Copy folder |
FolderApi | CreateFolder | Put /barcode/storage/folder/{path} | Create the folder |
FolderApi | DeleteFolder | Delete /barcode/storage/folder/{path} | Delete folder |
FolderApi | GetFilesList | Get /barcode/storage/folder/{path} | Get all files and folders within a folder |
FolderApi | MoveFolder | Put /barcode/storage/folder/move/{srcPath} | Move folder |
StorageApi | GetDiscUsage | Get /barcode/storage/disc | Get disc usage |
StorageApi | GetFileVersions | Get /barcode/storage/version/{path} | Get file versions |
StorageApi | ObjectExists | Get /barcode/storage/exist/{path} | Check if file or folder exists |
StorageApi | StorageExists | Get /barcode/storage/{storageName}/exist | Check if storage exists |
Documentation For Models
- ApiError
- ApiErrorResponse
- AustralianPostParams
- AutoSizeMode
- AvailableGraphicsUnit
- AztecEncodeMode
- AztecParams
- AztecSymbolMode
- BarcodeResponse
- BarcodeResponseList
- BorderDashStyle
- CaptionParams
- ChecksumValidation
- CodabarChecksumMode
- CodabarParams
- CodabarSymbol
- CodablockParams
- Code128Emulation
- Code128EncodeMode
- Code128Params
- Code16KParams
- CodeLocation
- CouponParams
- CustomerInformationInterpretingType
- DataBarParams
- DataMatrixEccType
- DataMatrixEncodeMode
- DataMatrixParams
- DataMatrixVersion
- DecodeBarcodeType
- DiscUsage
- DotCodeEncodeMode
- DotCodeParams
- EciEncodings
- EnableChecksum
- EncodeBarcodeType
- ErrorDetails
- FileVersions
- FilesList
- FilesUploadResult
- FontMode
- FontParams
- FontStyle
- GeneratorParams
- GeneratorParamsList
- HanXinEncodeMode
- HanXinErrorLevel
- HanXinParams
- HanXinVersion
- Itf14BorderType
- ItfParams
- MacroCharacter
- MaxiCodeEncodeMode
- MaxiCodeMode
- MaxiCodeParams
- ModelError
- ObjectExist
- Padding
- PatchCodeParams
- PatchFormat
- Pdf417CompactionMode
- Pdf417ErrorLevel
- Pdf417MacroTerminator
- Pdf417Params
- PostalParams
- PresetType
- QrEncodeMode
- QrEncodeType
- QrErrorLevel
- QrParams
- QrVersion
- ReaderParams
- RegionPoint
- ResultImageInfo
- StorageExist
- StorageFile
- StructuredAppend
- TextAlignment
- FileVersion