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*()for types,Req()/Conf()for messages) - β OCPP 1.6 Compliance - Strict adherence to protocol specification
- β
OCPP Naming - Uses
Req()/Conf()to match OCPP terminology (Authorize.req, Authorize.conf) - β Immutable Types - Thread-safe by design with value receivers
- β Comprehensive Testing - Unit tests and example tests with 100% coverage
- β 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 # Shared error constants and sentinels
β βββ doc.go # Package documentation
β βββ tests/ # Public API tests (black-box)
βββ messages/
β βββ authorize/ # Authorize message implementation
β βββ request.go # Authorize.req message (Req constructor)
β βββ errors.go # Package-level error constants
β βββ doc.go # Package documentation
β βββ types/ # Authorize-specific types
β βββ idtoken.go # IdToken type
β βββ idtaginfo.go # IdTagInfo type with builder pattern
β βββ authorizationstatus.go # AuthorizationStatus enum
β βββ errors.go # Type-level error constants
β βββ doc.go # Package documentation
β βββ tests/ # Public API 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
}Messages use OCPP terminology with Req() for requests and Conf() for responses:
import "github.com/aasanchez/ocpp16messages/messages/authorize"
// Create an Authorize.req message using the ReqInput struct
// Validation happens automatically in the constructor
req, err := authorize.Req(authorize.ReqInput{
IdTag: "RFID-ABC123",
})
if err != nil {
// Handle validation error (empty, too long, or invalid characters)
}
// Access the validated IdTag
fmt.Println(req.IdTag.String()) // "RFID-ABC123"The ReqMessage type returned by Req() contains validated, typed fields that are
immutable and thread-safe.
- Go 1.24+
- golangci-lint
- staticcheck
- gci, gofumpt, golines (formatters)
# Install dependencies
go mod tidy
# Run tests
make test # Unit tests with coverage
make test-coverage # Generate HTML coverage report
make test-example # Run example tests (documentation tests)
make test-all # Run 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 - Authorize.req (
authorize.Req()) - π§ Additional messages in development
- OCPP Naming - Messages use
Req()/Conf()to match OCPP terminology - Constructor Validation - All types require constructors that validate input
- Input Struct Pattern - Raw values passed via
ReqInput/ConfInputstructs, validated automatically - 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 - Designed for safe concurrent use
- 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