Skip to content

Replace ozzo-validation with pkg/valid#240

Merged
nt0xa merged 2 commits into
mainfrom
refactor/validation
Jun 15, 2026
Merged

Replace ozzo-validation with pkg/valid#240
nt0xa merged 2 commits into
mainfrom
refactor/validation

Conversation

@nt0xa

@nt0xa nt0xa commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Summary

Consolidates validation onto the in-house pkg/valid and removes the ozzo-validation dependency. Two related changes on this branch:

  1. Nested struct validation in pkg/validStruct(name, Validatable) folds a nested value's problems into the flat map with namespaced keys (field.nested.field), composing to any depth. Field/Validatable collapsed into one interface.
  2. Migrate config validation off ozzo — server, client, and module configs now validate via pkg/valid.

Details

  • pkg/valid additions: pure IP/Domain/URL string rules; Problems.Error() so a Problems can be returned where an error is expected.
  • Config Validate() returns valid.Problems; nested configs compose via valid.Struct (keys like tls.custom.key, modules.lark.app_id).
  • Conditionals: ozzo When / dynamic []FieldRules become plain-Go conditional field lists; the client's context-based cross-field check (context.server ∈ servers) moves into Config.Validate.
  • File/Directory become local rules in internal/cmd/server; internal/utils/valid is removed.
  • Bug fixes folded in: slack and api modules are now validated when enabled (previously skipped); lark Mode is now required.
  • Dropped the v import alias for pkg/valid now that the utils/valid name collision is gone.
  • ozzo removed from go.mod/go.sum.

Verification

  • go build ./..., go vet ./...
  • go test ./pkg/valid/ ./tests/ (incl. new format-rule, Problems.Error, and negative-config tests)
  • make lint — 0 issues
  • make build/client build/server

nt0xa added 2 commits June 15, 2026 22:17
Collapse Field and Validatable into a single Validatable interface
returning Problems, so leaf fields and domain types share one shape.
Add Struct(name, Validatable) which folds a nested value's problems into
the flat map with namespaced keys (field.nested.field), composing to any
depth. A nil value is skipped for optional nested structs.
Migrate all configuration validation (server, client, and module configs)
from ozzo-validation to the in-house pkg/valid, dropping the ozzo dependency
so the codebase has a single validation library.

- pkg/valid: add IP/Domain/URL string rules and a Problems.Error() so a
  Problems can be returned where an error is expected.
- Config Validate() methods now return valid.Problems; nested configs compose
  via valid.Struct (keys like tls.custom.key, modules.lark.app_id).
- ozzo's When/dynamic FieldRules become plain-Go conditional field lists; the
  client's context-based cross-field check moves into Config.Validate.
- File/Directory become local rules in internal/cmd/server; internal/utils/valid
  is removed.
- Validate slack and api modules when enabled (previously skipped); make lark
  Mode required.
- Drop the pkg/valid "v" import alias now that the utils/valid collision is gone.
@nt0xa nt0xa added maintenance Deps update, tool changes, configuration changes minor Minor changes labels Jun 15, 2026
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.00000% with 146 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.40%. Comparing base (a367f81) to head (d95e98c).

Files with missing lines Patch % Lines
internal/cmd/server/config.go 0.00% 34 Missing ⚠️
cmd/client/config.go 0.00% 15 Missing ⚠️
internal/modules/lark/config.go 0.00% 12 Missing ⚠️
internal/cmd/server/modules.go 0.00% 9 Missing ⚠️
internal/service/http_routes_create.go 0.00% 6 Missing ⚠️
internal/modules/api/config.go 0.00% 5 Missing ⚠️
internal/modules/slack/config.go 0.00% 5 Missing ⚠️
internal/service/http_routes_update.go 0.00% 5 Missing ⚠️
internal/modules/telegram/config.go 0.00% 4 Missing ⚠️
internal/service/dns_records_delete.go 0.00% 4 Missing ⚠️
... and 15 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   42.06%   42.40%   +0.33%     
==========================================
  Files         210      213       +3     
  Lines        8052     8068      +16     
==========================================
+ Hits         3387     3421      +34     
+ Misses       4384     4366      -18     
  Partials      281      281              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nt0xa nt0xa merged commit de5408f into main Jun 15, 2026
3 of 4 checks passed
@nt0xa nt0xa deleted the refactor/validation branch June 15, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Deps update, tool changes, configuration changes minor Minor changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant