examples/

directory
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT

README ΒΆ

EDIFACT Library Examples

This directory contains minimal examples demonstrating all features of the github.com/looksocial/edifact library.

πŸš€ Quick Start

Each example is self-contained and can be run independently:

# Run any example
go run 01_basic_reader/main.go
go run 02_generic_converter/main.go
# ... etc

πŸ“‹ Examples Overview

01_basic_reader

Feature: Basic EDIFACT message reading and parsing

  • Read EDIFACT strings into structured data
  • Access message type and segments
  • Basic segment and element traversal
go run 01_basic_reader/main.go
02_generic_converter

Feature: Generic EDIFACT to JSON conversion

  • Convert any EDIFACT message to JSON
  • Convert to structured data
  • Works with any message type
go run 02_generic_converter/main.go
03_message_detector

Feature: Message type detection

  • Detect message type from UNH segment
  • Get full message information (type, version, release)
  • Handle multiple message types
go run 03_message_detector/main.go
04_custom_config

Feature: Custom EDIFACT configuration

  • Configure delimiters and separators
  • Use custom configuration with all components
  • Test configuration consistency
go run 04_custom_config/main.go
05_segment_access

Feature: Advanced segment and element access

  • Access segments by tag
  • Get multiple segments of same type
  • Access elements by position
  • Access components within elements
go run 05_segment_access/main.go
06_error_handling

Feature: Comprehensive error handling

  • Handle parsing errors gracefully
  • Test different error scenarios
  • Validate error types and messages
go run 06_error_handling/main.go
07_validation

Feature: Message validation

  • Structure validation
  • Business rule validation
  • Custom validation logic
  • Segment count validation
go run 07_validation/main.go
08_performance

Feature: Performance testing and optimization

  • Benchmark reading performance
  • Benchmark conversion performance
  • Memory usage comparison
  • Concurrent processing simulation
go run 08_performance/main.go

🎯 What Each Example Demonstrates

Example Core Features Advanced Features
01_basic_reader βœ… Message parsing
βœ… Segment access
βœ… Element traversal
02_generic_converter βœ… JSON conversion
βœ… Structured data
βœ… Any message type
03_message_detector βœ… Type detection
βœ… Version detection
βœ… Multiple types
04_custom_config βœ… Custom delimiters
βœ… Configuration consistency
05_segment_access βœ… Tag-based access
βœ… Position-based access
βœ… Component access
βœ… Multiple segments
βœ… Advanced queries
06_error_handling βœ… Error scenarios
βœ… Graceful handling
βœ… Error classification
βœ… Recovery strategies
07_validation βœ… Structure validation
βœ… Business rules
βœ… Custom validation
βœ… Cross-field validation
08_performance βœ… Performance metrics
βœ… Throughput testing
βœ… Memory analysis
βœ… Concurrent processing

πŸ”§ Running Examples

Prerequisites
# Ensure you're in the project root
cd /path/to/edifact

# Install dependencies
go mod tidy
Run Individual Examples
# Basic reading
go run examples/01_basic_reader/main.go

# Generic conversion
go run examples/02_generic_converter/main.go

# Message detection
go run examples/03_message_detector/main.go

# Custom configuration
go run examples/04_custom_config/main.go

# Segment access
go run examples/05_segment_access/main.go

# Error handling
go run examples/06_error_handling/main.go

# Validation
go run examples/07_validation/main.go

# Performance
go run examples/08_performance/main.go
Run All Examples
# Run all examples in sequence
for dir in examples/*/; do
    echo "Running $(basename $dir)..."
    go run $dir/main.go
    echo "---"
done

πŸ“Š Expected Output

Each example provides clear, formatted output showing:

  • Feature demonstration: What the feature does
  • Input data: Sample EDIFACT messages used
  • Processing results: Parsed data, conversions, validations
  • Performance metrics: Timing and throughput information (where applicable)
  • Error handling: How errors are handled and reported

πŸŽ“ Learning Path

For a structured learning experience, follow this order:

  1. 01_basic_reader - Start with basic parsing
  2. 02_generic_converter - Learn about conversion
  3. 03_message_detector - Understand message types
  4. 04_custom_config - Configure the library
  5. 05_segment_access - Advanced data access
  6. 06_error_handling - Robust error handling
  7. 07_validation - Data validation
  8. 08_performance - Performance optimization

πŸ” Example Data

All examples use realistic EDIFACT messages:

  • INVOIC: Invoice messages with line items
  • IFTMIN: Transport instruction messages
  • ORDERS: Purchase order messages
  • Mixed types: Various message types for testing

🀝 Contributing

To add new examples:

  1. Create a new directory with descriptive name
  2. Include a main.go file with complete example
  3. Add documentation to this README
  4. Test the example thoroughly

Note: These examples demonstrate the core functionality. For more advanced usage patterns and real-world applications, see the edifact-examples repository.

Jump to

Keyboard shortcuts

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