Added CompleteCode function.
All checks were successful
CI / test (push) Successful in 17s

This commit is contained in:
2026-02-21 04:19:19 +01:00
parent 50e9036400
commit 22ca29b4af
5 changed files with 110 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ Copyright (c) 2026 Micha Hoiting
high-integrity identifiers. It maps a compact 32-bit integer space to a
human-readable serial format:
```
```text
LLL-NNN-LC
```
@@ -18,6 +18,12 @@ Where:
- `N` = number (`100``999`)
- `C` = checksum letter (`A``Z`)
For instance
```text
ABC-123-DT
```
## What it provides
- 4 data letters
@@ -77,6 +83,8 @@ func main() {
- Parses and validates `LLL-NNN-LC`, checks checksum, and returns the deterministic index.
- `serial.Decode(idx uint32) (string, error)`
- Converts a valid index back to `LLL-NNN-LC`.
- `serial.CompleteCode(codeWithoutChecksum string) (string, uint32, error)`
- Takes `LLL-NNN-L` and returns the completed `LLL-NNN-LC` plus index.
- `serial.RandomCode(isInUse ...func(uint32) bool) (string, uint32, error)`
- Generates a random valid `LLL-NNN-LC` code and its corresponding index.
- If provided, the callback is used to skip indices already in use by the client.
@@ -108,6 +116,7 @@ make test
Exported errors:
- `serial.ErrInvalidFormat`
- `serial.ErrInvalidFormatNoChecksum`
- `serial.ErrInvalidLetters`
- `serial.ErrForbiddenLetterTriplet`
- `serial.ErrInvalidNumber`