A type-safe, OCPP 1.6-compliant Go library providing message structures and validation for Electric Vehicle charging station communication.
This library implements OCPP (Open Charge Point Protocol) 1.6 message types with strict validation, following Go best practices and the official OCPP 1.6 specification. It is designed as a foundation for building OCPP-compliant charging station management systems and charge point implementations.
Status: π§ Active Development (Pre-1.0)
- β
Type Safety - Constructor pattern with validation (
New*()functions) - β OCPP 1.6 Compliance - Strict adherence to protocol specification
- β Immutable Types - Thread-safe by design with value receivers
- β Comprehensive Testing - Unit, integration, race, and fuzz tests
- β Zero Panics - All errors returned, never panicked
- β Well Documented - Full godoc coverage and examples
go get github.com/aasanchez/ocpp16messagesRequirements: Go 1.24 or later
.
βββ shared/types/ # Core OCPP data types
β βββ cistring.go # CiString20/25/50/255/500 types
β βββ datetime.go # RFC3339 DateTime with UTC normalization
β βββ integer.go # Validated uint16 Integer type
β βββ errors.go # Reusable error constructors
β βββ tests/ # Unit and integration tests
βββ messages/
β βββ authorize/ # Authorize message implementation
β βββ request.go # Authorize request message
β βββ types/ # Authorize-specific types
β βββ idtoken.go # IdToken type
β βββ request.go # Request payload
β βββ tests/ # Message-specific tests
βββ SECURITY.md # Security policy and vulnerability reporting
The library provides validated OCPP 1.6 data types:
import "github.com/aasanchez/ocpp16messages/shared/types"
// CiString types (case-insensitive, ASCII printable, length-validated)
idTag, err := types.NewCiString20Type("RFID-ABC123")
if err != nil {
// Handle validation error (length > 20 or non-ASCII chars)
}
// DateTime (RFC3339, auto-normalized to UTC)
timestamp, err := types.NewDateTime("2025-01-02T15:04:05Z")
if err != nil {
// Handle parsing error
}
// Integer (validated uint16)
retryCount, err := types.NewInteger("3")
if err != nil {
// Handle conversion/range error
}import (
"github.com/aasanchez/ocpp16messages/messages/authorize"
mat "github.com/aasanchez/ocpp16messages/messages/authorize/types"
)
// Create request payload
payload := mat.Request{
IdTag: "RFID-ABC123",
}
// Validate payload
if err := payload.Validate(); err != nil {
// Handle validation error
}
// Create message
request, err := authorize.NewRequest(payload)
if err != nil {
// Handle construction error
}- Go 1.24+
- golangci-lint
- staticcheck
- gci, gofumpt, golines (formatters)
# Install dependencies
go mod tidy
# Run tests
make test # Unit and example tests
make test-coverage # Generate HTML coverage report
make test-race # Race detector (concurrency safety)
make test-fuzz # Fuzz tests (10s per function, configurable with FUZZTIME)
make test-all # All test types
# Code quality
make lint # Run all linters (golangci-lint, go vet, staticcheck)
make format # Format code (gci, gofumpt, golines, gofmt)
# Documentation
make pkgsite # Start local documentation server at http://localhost:8080Reports are generated in the reports/ directory:
reports/coverage.out- Coverage datareports/golangci-lint.txt- Lint results
| OCPP Type | Go Type | Validation |
|---|---|---|
| CiString20Type | types.CiString20Type |
Length β€ 20, ASCII printable (32β126) |
| CiString25Type | types.CiString25Type |
Length β€ 25, ASCII printable (32β126) |
| CiString50Type | types.CiString50Type |
Length β€ 50, ASCII printable (32β126) |
| CiString255Type | types.CiString255Type |
Length β€ 255, ASCII printable (32β126) |
| CiString500Type | types.CiString500Type |
Length β€ 500, ASCII printable (32β126) |
| dateTime | types.DateTime |
RFC3339, normalized to UTC |
| integer | types.Integer |
uint16 (0β65535) |
- β Authorize - Request/Response
- π§ Additional messages in development
- Constructor Validation - All types require
New*()constructors that validate input - Immutability - Types use private fields and value receivers
- Error Wrapping - Context preserved via
fmt.Errorfwith%w - No Panics - Library never panics; all errors returned
- Thread Safety - All types proven safe via race tests
- Go Conventions - Follows Effective Go guidelines
Security is critical for EV charging infrastructure. This library:
- Validates all input at construction time
- Prevents injection attacks via strict type constraints
- Provides clear error messages without exposing internals
- Uses immutable types to prevent tampering
- Is designed for safe concurrent use
Reporting vulnerabilities: See SECURITY.md for our security policy and responsible disclosure process.
We welcome contributions! Please:
- Follow Go best practices and Effective Go
- Add tests for all new functionality
- Ensure
make test-allpasses - Run
make lintandmake formatbefore committing - Document all exported types and functions
- Follow the existing code style
See CLAUDE.md for detailed development guidelines.
See LICENSE