The Best Go API for Shipping Container OCR

Stop using regex. Extract structured data from Shipping Containers with 99% accuracy using Go.

Shipping Container OCR extraction process diagram
StructOCR transforms raw Shipping Container images into validated JSON.

The Problem with Shipping Container Parsing in Go

Extracting shipping container numbers from images presents severe technical hurdles for Go-based backend systems. Container IDs are often printed vertically, heavily rusted, or physically damaged. Terminal gate cameras capture images at skewed angles, in low light, or with heavy shadows. Attempting to use standard OCR libraries or building custom regex parsers for ISO 6346 validation is notoriously unreliable due to these real-world inconsistencies, leading to automated gate bottlenecks and high manual review costs.

The StructOCR Solution

StructOCR leverages advanced deep learning models specifically trained to overcome these port and yard challenges. Our AI automatically corrects perspective distortion, deskews images, and accurately reads vertical or degraded text. We provide an ISO 6346 compliant extraction out of the box. Returning validated, structured JSON directly to your application in under 5 seconds, it is the ideal solution for seamless integration into your logistics and port automation systems.

Common Use Cases

  • Terminal Automation: Speed up gate operations and yard management by instantly capturing container numbers via Go microservices.
  • Customs & Compliance: Automate cross-border document verification and manifesting.
  • Asset Tracking: Monitor shipping container movements across the global supply chain with real-time data ingestion.

Live Demo: Container OCR

No registration required. Upload a file to test the extraction.

1
Upload
2
Results

Drop files here or click to browse

JPG · PNG · WebP  ·  up to 500 files · max 4.5 MB each

No files selected
Need more testing? Create a free account to get 200 free credits (equals 200 Container scans).

Implementation: Raw API Request

Complete, runnable Go code to extract data from a Shipping Container. Note: StructOCR efficiently handles direct file uploads via standard HTTP requests.

Prerequisite: Go 1.16+

CODE EXAMPLE
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register

package main

import (
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	apiKey := "YOUR_API_KEY" // Replace with your actual API key
	imagePath := "./container_image.jpg" // Replace with the path to your image

	// 1. Open the image file directly (StructOCR supports direct file upload)
	file, err := os.Open(imagePath)
	if err != nil {
		fmt.Println("Error opening file:", err)
		os.Exit(1)
	}
	defer file.Close()

	// 2. Create a new HTTP request targeting the container endpoint
	req, err := http.NewRequest("POST", "https://api.structocr.com/v1/container", file)
	if err != nil {
		fmt.Println("Error creating request:", err)
		os.Exit(1)
	}

	// 3. Set the required headers for binary file upload
	req.Header.Set("x-api-key", apiKey)
	req.Header.Set("Content-Type", "application/octet-stream")

	// 4. Make the API request
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		fmt.Println("Error making API request:", err)
		os.Exit(1)
	}
	defer res.Body.Close()

	// 5. Parse the response body
	body, _ := io.ReadAll(res.Body)
	var response map[string]interface{}
	err = json.Unmarshal(body, &response)
	if err != nil {
		fmt.Println("Error decoding JSON response:", err)
		os.Exit(1)
	}

	// 6. Handle the API response
	if success, ok := response["success"].(bool); ok && success {
		if data, ok := response["data"].(map[string]interface{}); ok {
			fmt.Println("✅ Extraction Successful!\n")
			
			if containerNum, exists := data["container_number"].(string); exists {
				fmt.Println("Container Number:", containerNum)
			}
			if isValid, exists := data["is_valid"].(bool); exists {
				fmt.Println("Is Valid (ISO 6346):", isValid)
			}
			if conf, exists := data["confidence"].(string); exists {
				fmt.Println("Confidence:", conf)
			}

			// Accessing parsed components
			if parsed, exists := data["parsed"].(map[string]interface{}); exists {
				fmt.Println("\n--- Parsed Details ---")
				fmt.Printf("Owner Code: %v\n", parsed["owner_code"])
				fmt.Printf("Category: %v\n", parsed["category"])
				fmt.Printf("Serial Number: %v\n", parsed["serial_number"])
				fmt.Printf("Check Digit: %v\n", parsed["check_digit"])
			}
		} else {
			fmt.Println("Error: 'data' payload missing.")
		}
	} else {
		fmt.Println("❌ Extraction Failed.")
		if msg, ok := response["error"].(string); ok {
			fmt.Println("Error Message:", msg)
		}
	}
}

Technical Specs

  • Latency: < 4s (Average)
  • Uptime: 99.9% SLA
  • Security: AES-256 Encryption & SOC2 Compliant
  • Input: JPG, PNG, WebP (Max 4.5MB) via Direct File Upload
  • Output: JSON (Structured Data)

Key Features

  • Smart Crop: Auto-detects container boundaries.
  • ISO 6346 Validation: Cross-validates owner codes and checksums automatically.
  • Specialized Models: Trained specifically on vertical and degraded Shipping Container text.

Sample JSON Response

The API returns a clean JSON object with normalized, parsed container fields.

{
  "success": true,
  "data": {
    "container_number": "TTNU5194822",
    "is_valid": true,
    "confidence": "High",
    "parsed": {
      "owner_code": "TTN",
      "category": "U",
      "serial_number": "519482",
      "check_digit": "2"
    }
  }
}

Frequently Asked Questions

What file formats are supported?

JPG, PNG, and WebP images up to 4.5MB.

Is data stored?

No. Images are processed in-memory and deleted immediately.

How to handle errors?

Check the 'success' flag and 'error' message in the response.

You May Also Like

Related tutorials, platform guides, and comparisons

Tutorial

PHP Shipping Container OCR API

Tutorial: Learn how to use the StructOCR PHP Client via cURL for shipping container OCR. Upload an image for a free test! Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schemas.

PHP · Container
Tutorial

Java Shipping Container OCR API

Upload an image for a free test! Tutorial: Learn how to use the StructOCR Java Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy.

Java · Container
Tutorial

C# Shipping Container OCR API

Upload an image for a free test! Tutorial: Learn how to use the StructOCR C# Client to extract data from Shipping Containers. Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schemas.

C# · Container
Tutorial

Node.js Shipping Container OCR API

Tutorial: How to use the StructOCR Node.js SDK to extract data from Shipping Containers. Upload an image for a free test! Includes code samples and JSON schema.

Node.js · Container
Tutorial

Python Shipping Container OCR API

Tutorial: Learn how to use the StructOCR Python SDK for shipping container OCR. Upload an image for a free test! Extract ISO 6346 container numbers with 99% accuracy. Includes code samples and JSON schemas.

Python · Container
Tutorial

Go Receipt OCR API

Upload an image for a free test! Tutorial: Build scalable expense reporting apps in Go. Learn how to extract merchants, line items, and totals from POS receipts using our Golang OCR integration.

Go · Receipt
Country Tutorial

Canada Driver License OCR with Python SDK

Extract structured fields from a Canada provincial driver licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Bulgaria Passport OCR with Python SDK

Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Bulgaria passports with a server-side integration.

Python · Passport
Country Tutorial

Bulgaria Passport OCR with Node.js SDK

Use the official StructOCR Node.js SDK with TypeScript and Express to extract structured MRZ and VIZ data from Bulgaria passports.

Node.js · Passport
Country Tutorial

Canada Driver License OCR with Node.js SDK

Extract structured fields from a Canada provincial driver licence with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

From tutorial to production in 5 minutes.

You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.

Instant Access Cancel Anytime 99.9% Uptime