aspose-barcode-cloud-go

module
v1.2403.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2024 License: MIT

README

Aspose.BarCode Cloud SDK for Go

License Go GitHub tag (latest SemVer)

  • API version: 3.0
  • SDK version: 1.2403.0

Demo applications

Scan QR Generate Barcode Recognize Barcode
ScanQR Generate Recognize
Generate Wi-Fi QR Embed Barcode Scan Barcode
Wi-FiQR Embed Scan

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

  1. Go to existing module directory, or create a new module (see https://blog.golang.org/using-go-modules)

  2. Run go get command

    go get -u github.com/aspose-barcode-cloud/aspose-barcode-cloud-go@v1.2403.0
    
Using GOPATH (for Go < 1.11 )
  1. Run go get command outside module directory

    go 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"
    "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"
)

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)
}
Recognize a barcode on image

The examples below show how you can recognize barcode text and type on the image using barcode:

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"
)

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)
    }
}

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 &quot;application/octet-stream&quot;. 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
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

Directories

Path Synopsis
jwt
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL