service backend
All checks were successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful

This commit is contained in:
Stephan D
2025-11-07 18:35:26 +01:00
parent 20e8f9acc4
commit 62a6631b9a
537 changed files with 48453 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package ledger
// ValidationIssue describes a single validation problem.
type ValidationIssue struct {
Field string `json:"field"`
Code string `json:"code"`
Msg string `json:"msg"`
}
// ValidationError aggregates issues. Implements error without fmt/errors.
type ValidationError struct {
Issues []ValidationIssue `json:"issues"`
}
func (e *ValidationError) Error() string {
if e == nil || len(e.Issues) == 0 {
return ""
}
if len(e.Issues) == 1 {
return e.Issues[0].Field + ": " + e.Issues[0].Msg
}
return "validation failed"
}
// veAdd appends a new issue into a (possibly nil) *ValidationError.
func veAdd(e **ValidationError, field, code, msg string) {
if *e == nil {
*e = &ValidationError{Issues: make([]ValidationIssue, 0, 4)}
}
(*e).Issues = append((*e).Issues, ValidationIssue{Field: field, Code: code, Msg: msg})
}