Replace ozzo-validation with pkg/valid#240
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidates validation onto the in-house
pkg/validand removes theozzo-validationdependency. Two related changes on this branch:pkg/valid—Struct(name, Validatable)folds a nested value's problems into the flat map with namespaced keys (field.nested.field), composing to any depth.Field/Validatablecollapsed into one interface.pkg/valid.Details
pkg/validadditions: pureIP/Domain/URLstring rules;Problems.Error()so aProblemscan be returned where anerroris expected.Validate()returnsvalid.Problems; nested configs compose viavalid.Struct(keys liketls.custom.key,modules.lark.app_id).When/ dynamic[]FieldRulesbecome plain-Go conditional field lists; the client's context-based cross-field check (context.server ∈ servers) moves intoConfig.Validate.File/Directorybecome local rules ininternal/cmd/server;internal/utils/validis removed.slackandapimodules are now validated when enabled (previously skipped); larkModeis now required.vimport alias forpkg/validnow that theutils/validname collision is gone.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 issuesmake build/client build/server