Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add Validators to ExportedConfigs and "config verify" command. #154

Merged
merged 13 commits into from
Jul 22, 2021
Merged

Conversation

Reasno
Copy link
Member

@Reasno Reasno commented Jul 20, 2021

This PR allows each module to export a verification function. Once the configuration is loaded/reloaded, all verifications are run one by one. if an error is raised, the process will exit.

@Reasno Reasno marked this pull request as draft July 20, 2021 05:37
@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #154 (073a657) into master (029ce55) will increase coverage by 15.31%.
The diff coverage is 86.64%.

❗ Current head 073a657 differs from pull request most recent head cfc2fcb. Consider uploading reports for the commit cfc2fcb to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           master     #154       +/-   ##
===========================================
+ Coverage   64.84%   80.16%   +15.31%     
===========================================
  Files          77       90       +13     
  Lines        2677     3837     +1160     
===========================================
+ Hits         1736     3076     +1340     
+ Misses        793      547      -246     
- Partials      148      214       +66     
Impacted Files Coverage Δ
config/watcher/signal.go 75.00% <ø> (ø)
contract/context.go 100.00% <ø> (ø)
events/event.go 100.00% <ø> (ø)
http_func.go 100.00% <ø> (ø)
otgorm/log.go 66.66% <ø> (ø)
otkafka/log.go 100.00% <ø> (ø)
queue/packer.go 75.00% <ø> (ø)
srvhttp/docs.go 0.00% <ø> (ø)
srvhttp/encode.go 77.41% <ø> (ø)
srvhttp/healthcheck.go 0.00% <ø> (ø)
... and 108 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee3fa4d...cfc2fcb. Read the comment docs.

@Reasno Reasno marked this pull request as ready for review July 20, 2021 06:23

// Validator is a method to verify if config is valid. If it is not valid, the
// returned error should contain a human readable description of why.
type Validator func(data map[string]interface{}) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use type ConfigAccessor as argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfigAccessor is an interface. Data is data. Validation validates the data, not the interface.

Copy link
Member Author

@Reasno Reasno Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interfaces describe behavior, not data.

GGXXLL
GGXXLL previously approved these changes Jul 21, 2021
@Reasno Reasno changed the title feat: add verification command feat: add config verification to ExportedConfigs and "config verify" command. Jul 21, 2021
@Reasno Reasno requested a review from GGXXLL July 21, 2021 16:02
@Reasno Reasno changed the title feat: add config verification to ExportedConfigs and "config verify" command. feat(config): add Validators to ExportedConfigs and "config verify" command. Jul 21, 2021
@Reasno Reasno merged commit d5c3b8a into DoNewsCode:master Jul 22, 2021
@Reasno Reasno deleted the config branch July 22, 2021 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants